@canva/cli 1.19.0 → 1.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (231) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/README.md +1 -9
  3. package/cli.js +625 -626
  4. package/package.json +2 -3
  5. package/templates/base/backend/base_backend/create.ts +0 -114
  6. package/templates/base/backend/database/database.ts +0 -42
  7. package/templates/base/backend/routers/auth.ts +0 -288
  8. package/templates/base/declarations/declarations.d.ts +0 -29
  9. package/templates/base/eslint.config.mjs +0 -14
  10. package/templates/base/package.json +0 -91
  11. package/templates/base/scripts/copy_env.ts +0 -13
  12. package/templates/base/scripts/ssl/ssl.ts +0 -131
  13. package/templates/base/scripts/start/app_runner.ts +0 -223
  14. package/templates/base/scripts/start/context.ts +0 -171
  15. package/templates/base/scripts/start/start.ts +0 -46
  16. package/templates/base/scripts/start.tests.ts +0 -61
  17. package/templates/base/styles/components.css +0 -38
  18. package/templates/base/tsconfig.json +0 -56
  19. package/templates/base/webpack.config.ts +0 -247
  20. package/templates/common/.env.template +0 -6
  21. package/templates/common/.gitignore.template +0 -8
  22. package/templates/common/.nvmrc +0 -1
  23. package/templates/common/.prettierrc +0 -21
  24. package/templates/common/LICENSE.md +0 -48
  25. package/templates/common/README.md +0 -179
  26. package/templates/common/jest.config.mjs +0 -35
  27. package/templates/common/jest.setup.ts +0 -35
  28. package/templates/content_publisher/README.md +0 -58
  29. package/templates/content_publisher/canva-app.json +0 -17
  30. package/templates/content_publisher/declarations/declarations.d.ts +0 -29
  31. package/templates/content_publisher/eslint.config.mjs +0 -14
  32. package/templates/content_publisher/package.json +0 -90
  33. package/templates/content_publisher/scripts/copy_env.ts +0 -13
  34. package/templates/content_publisher/scripts/ssl/ssl.ts +0 -131
  35. package/templates/content_publisher/scripts/start/app_runner.ts +0 -223
  36. package/templates/content_publisher/scripts/start/context.ts +0 -171
  37. package/templates/content_publisher/scripts/start/start.ts +0 -46
  38. package/templates/content_publisher/src/index.tsx +0 -4
  39. package/templates/content_publisher/src/intents/content_publisher/index.tsx +0 -107
  40. package/templates/content_publisher/src/intents/content_publisher/post_preview.tsx +0 -240
  41. package/templates/content_publisher/src/intents/content_publisher/preview_ui.tsx +0 -62
  42. package/templates/content_publisher/src/intents/content_publisher/settings_ui.tsx +0 -81
  43. package/templates/content_publisher/src/intents/content_publisher/types.ts +0 -29
  44. package/templates/content_publisher/styles/components.css +0 -38
  45. package/templates/content_publisher/styles/preview_ui.css +0 -49
  46. package/templates/content_publisher/tsconfig.json +0 -56
  47. package/templates/content_publisher/webpack.config.ts +0 -247
  48. package/templates/dam/backend/routers/dam.ts +0 -108
  49. package/templates/dam/backend/server.ts +0 -65
  50. package/templates/dam/canva-app.json +0 -25
  51. package/templates/dam/declarations/declarations.d.ts +0 -29
  52. package/templates/dam/eslint.config.mjs +0 -14
  53. package/templates/dam/package.json +0 -97
  54. package/templates/dam/scripts/copy_env.ts +0 -13
  55. package/templates/dam/scripts/ssl/ssl.ts +0 -131
  56. package/templates/dam/scripts/start/app_runner.ts +0 -223
  57. package/templates/dam/scripts/start/context.ts +0 -171
  58. package/templates/dam/scripts/start/start.ts +0 -46
  59. package/templates/dam/src/index.tsx +0 -4
  60. package/templates/dam/src/intents/design_editor/adapter.ts +0 -44
  61. package/templates/dam/src/intents/design_editor/app.tsx +0 -35
  62. package/templates/dam/src/intents/design_editor/config.ts +0 -220
  63. package/templates/dam/src/intents/design_editor/index.css +0 -3
  64. package/templates/dam/src/intents/design_editor/index.tsx +0 -25
  65. package/templates/dam/tsconfig.json +0 -56
  66. package/templates/dam/utils/backend/base_backend/create.ts +0 -114
  67. package/templates/dam/webpack.config.ts +0 -247
  68. package/templates/data_connector/README.md +0 -84
  69. package/templates/data_connector/canva-app.json +0 -21
  70. package/templates/data_connector/declarations/declarations.d.ts +0 -29
  71. package/templates/data_connector/eslint.config.mjs +0 -14
  72. package/templates/data_connector/package.json +0 -92
  73. package/templates/data_connector/scripts/copy_env.ts +0 -13
  74. package/templates/data_connector/scripts/ssl/ssl.ts +0 -131
  75. package/templates/data_connector/scripts/start/app_runner.ts +0 -223
  76. package/templates/data_connector/scripts/start/context.ts +0 -171
  77. package/templates/data_connector/scripts/start/start.ts +0 -46
  78. package/templates/data_connector/src/api/connect_client.ts +0 -6
  79. package/templates/data_connector/src/api/data_source.ts +0 -97
  80. package/templates/data_connector/src/api/data_sources/designs.tsx +0 -296
  81. package/templates/data_connector/src/api/data_sources/index.ts +0 -4
  82. package/templates/data_connector/src/api/data_sources/templates.tsx +0 -328
  83. package/templates/data_connector/src/api/fetch_data_table.ts +0 -55
  84. package/templates/data_connector/src/api/index.ts +0 -4
  85. package/templates/data_connector/src/api/oauth.ts +0 -8
  86. package/templates/data_connector/src/api/tests/data_source.test.tsx +0 -99
  87. package/templates/data_connector/src/components/app_error.tsx +0 -15
  88. package/templates/data_connector/src/components/footer.tsx +0 -26
  89. package/templates/data_connector/src/components/header.tsx +0 -40
  90. package/templates/data_connector/src/components/index.ts +0 -3
  91. package/templates/data_connector/src/components/inputs/messages.tsx +0 -95
  92. package/templates/data_connector/src/components/inputs/search_filter.tsx +0 -109
  93. package/templates/data_connector/src/components/inputs/select_field.tsx +0 -26
  94. package/templates/data_connector/src/context/app_context.tsx +0 -125
  95. package/templates/data_connector/src/context/index.ts +0 -2
  96. package/templates/data_connector/src/context/use_app_context.ts +0 -17
  97. package/templates/data_connector/src/index.tsx +0 -4
  98. package/templates/data_connector/src/intents/data_connector/app.tsx +0 -20
  99. package/templates/data_connector/src/intents/data_connector/entrypoint.tsx +0 -70
  100. package/templates/data_connector/src/intents/data_connector/home.tsx +0 -21
  101. package/templates/data_connector/src/intents/data_connector/index.tsx +0 -56
  102. package/templates/data_connector/src/pages/data_source_config.tsx +0 -9
  103. package/templates/data_connector/src/pages/error.tsx +0 -37
  104. package/templates/data_connector/src/pages/index.ts +0 -4
  105. package/templates/data_connector/src/pages/login.tsx +0 -145
  106. package/templates/data_connector/src/pages/select_source.tsx +0 -24
  107. package/templates/data_connector/src/routes/index.ts +0 -2
  108. package/templates/data_connector/src/routes/paths.ts +0 -7
  109. package/templates/data_connector/src/routes/protected_route.tsx +0 -26
  110. package/templates/data_connector/src/routes/routes.tsx +0 -42
  111. package/templates/data_connector/src/utils/data_params.ts +0 -17
  112. package/templates/data_connector/src/utils/data_table.ts +0 -116
  113. package/templates/data_connector/src/utils/fetch_result.ts +0 -36
  114. package/templates/data_connector/src/utils/index.ts +0 -2
  115. package/templates/data_connector/src/utils/tests/data_table.test.ts +0 -133
  116. package/templates/data_connector/styles/components.css +0 -38
  117. package/templates/data_connector/tsconfig.json +0 -56
  118. package/templates/data_connector/webpack.config.ts +0 -247
  119. package/templates/gen_ai/README.md +0 -27
  120. package/templates/gen_ai/backend/routers/image.ts +0 -232
  121. package/templates/gen_ai/backend/server.ts +0 -65
  122. package/templates/gen_ai/canva-app.json +0 -25
  123. package/templates/gen_ai/declarations/declarations.d.ts +0 -29
  124. package/templates/gen_ai/eslint.config.mjs +0 -14
  125. package/templates/gen_ai/package.json +0 -101
  126. package/templates/gen_ai/scripts/copy_env.ts +0 -13
  127. package/templates/gen_ai/scripts/ssl/ssl.ts +0 -131
  128. package/templates/gen_ai/scripts/start/app_runner.ts +0 -223
  129. package/templates/gen_ai/scripts/start/context.ts +0 -171
  130. package/templates/gen_ai/scripts/start/start.ts +0 -46
  131. package/templates/gen_ai/src/api/api.ts +0 -194
  132. package/templates/gen_ai/src/api/index.ts +0 -1
  133. package/templates/gen_ai/src/components/app_error.tsx +0 -18
  134. package/templates/gen_ai/src/components/footer.messages.ts +0 -48
  135. package/templates/gen_ai/src/components/footer.tsx +0 -156
  136. package/templates/gen_ai/src/components/image_grid.tsx +0 -103
  137. package/templates/gen_ai/src/components/index.ts +0 -7
  138. package/templates/gen_ai/src/components/loading_results.tsx +0 -169
  139. package/templates/gen_ai/src/components/prompt_input.messages.ts +0 -14
  140. package/templates/gen_ai/src/components/prompt_input.tsx +0 -154
  141. package/templates/gen_ai/src/components/remaining_credits.tsx +0 -84
  142. package/templates/gen_ai/src/components/report_box.tsx +0 -54
  143. package/templates/gen_ai/src/components/tests/remaining_credit.tests.tsx +0 -47
  144. package/templates/gen_ai/src/config.ts +0 -21
  145. package/templates/gen_ai/src/context/app_context.tsx +0 -153
  146. package/templates/gen_ai/src/context/context.messages.ts +0 -30
  147. package/templates/gen_ai/src/context/index.ts +0 -2
  148. package/templates/gen_ai/src/context/use_app_context.ts +0 -17
  149. package/templates/gen_ai/src/index.tsx +0 -4
  150. package/templates/gen_ai/src/intents/design_editor/app.tsx +0 -19
  151. package/templates/gen_ai/src/intents/design_editor/home.tsx +0 -13
  152. package/templates/gen_ai/src/intents/design_editor/index.tsx +0 -17
  153. package/templates/gen_ai/src/pages/error.tsx +0 -41
  154. package/templates/gen_ai/src/pages/generate.tsx +0 -9
  155. package/templates/gen_ai/src/pages/index.ts +0 -3
  156. package/templates/gen_ai/src/pages/results.tsx +0 -31
  157. package/templates/gen_ai/src/routes/index.ts +0 -1
  158. package/templates/gen_ai/src/routes/paths.ts +0 -4
  159. package/templates/gen_ai/src/routes/routes.tsx +0 -24
  160. package/templates/gen_ai/src/utils/index.ts +0 -1
  161. package/templates/gen_ai/src/utils/obscenity_filter.ts +0 -33
  162. package/templates/gen_ai/styles/components.css +0 -38
  163. package/templates/gen_ai/styles/utils.css +0 -3
  164. package/templates/gen_ai/tsconfig.json +0 -56
  165. package/templates/gen_ai/utils/backend/base_backend/create.ts +0 -114
  166. package/templates/gen_ai/webpack.config.ts +0 -247
  167. package/templates/hello_world/canva-app.json +0 -21
  168. package/templates/hello_world/declarations/declarations.d.ts +0 -29
  169. package/templates/hello_world/eslint.config.mjs +0 -14
  170. package/templates/hello_world/package.json +0 -90
  171. package/templates/hello_world/scripts/copy_env.ts +0 -13
  172. package/templates/hello_world/scripts/ssl/ssl.ts +0 -131
  173. package/templates/hello_world/scripts/start/app_runner.ts +0 -223
  174. package/templates/hello_world/scripts/start/context.ts +0 -171
  175. package/templates/hello_world/scripts/start/start.ts +0 -46
  176. package/templates/hello_world/src/index.tsx +0 -4
  177. package/templates/hello_world/src/intents/design_editor/app.tsx +0 -86
  178. package/templates/hello_world/src/intents/design_editor/index.tsx +0 -25
  179. package/templates/hello_world/src/intents/design_editor/tests/__snapshots__/app.tests.tsx.snap +0 -45
  180. package/templates/hello_world/src/intents/design_editor/tests/app.tests.tsx +0 -92
  181. package/templates/hello_world/styles/components.css +0 -38
  182. package/templates/hello_world/tsconfig.json +0 -56
  183. package/templates/hello_world/webpack.config.ts +0 -247
  184. package/templates/mls/README.md +0 -81
  185. package/templates/mls/canva-app.json +0 -25
  186. package/templates/mls/declarations/declarations.d.ts +0 -29
  187. package/templates/mls/eslint.config.mjs +0 -14
  188. package/templates/mls/jest.config.mjs +0 -36
  189. package/templates/mls/jest.setup.ts +0 -39
  190. package/templates/mls/package.json +0 -117
  191. package/templates/mls/scripts/copy_env.ts +0 -13
  192. package/templates/mls/scripts/ssl/ssl.ts +0 -131
  193. package/templates/mls/scripts/start/app_runner.ts +0 -223
  194. package/templates/mls/scripts/start/context.ts +0 -171
  195. package/templates/mls/scripts/start/start.ts +0 -46
  196. package/templates/mls/src/__tests__/app.tests.tsx +0 -11
  197. package/templates/mls/src/__tests__/office_selection_page.tests.tsx +0 -72
  198. package/templates/mls/src/__tests__/utils.tsx +0 -19
  199. package/templates/mls/src/adapter.ts +0 -126
  200. package/templates/mls/src/components/agent/agent_card.tsx +0 -57
  201. package/templates/mls/src/components/agent/agent_grid.tsx +0 -37
  202. package/templates/mls/src/components/agent/agent_list.tsx +0 -17
  203. package/templates/mls/src/components/agent/agent_search_filters.tsx +0 -88
  204. package/templates/mls/src/components/breadcrumb/breadcrumb.tsx +0 -40
  205. package/templates/mls/src/components/listing/listing_card.tsx +0 -64
  206. package/templates/mls/src/components/listing/listing_grid.tsx +0 -37
  207. package/templates/mls/src/components/listing/listing_list.tsx +0 -21
  208. package/templates/mls/src/components/listing/listing_search_filters.tsx +0 -145
  209. package/templates/mls/src/components/placeholders/placeholders.tsx +0 -65
  210. package/templates/mls/src/data.ts +0 -359
  211. package/templates/mls/src/index.tsx +0 -4
  212. package/templates/mls/src/intents/design_editor/app.tsx +0 -44
  213. package/templates/mls/src/intents/design_editor/index.tsx +0 -25
  214. package/templates/mls/src/pages/agent_details_page/agent_details_page.tsx +0 -175
  215. package/templates/mls/src/pages/list_page/agent_tab_panel.tsx +0 -126
  216. package/templates/mls/src/pages/list_page/list_page.tsx +0 -67
  217. package/templates/mls/src/pages/list_page/listing_tab_panel.tsx +0 -135
  218. package/templates/mls/src/pages/listing_details_page/listing_details_page.tsx +0 -418
  219. package/templates/mls/src/pages/loading_page/loading_page.tsx +0 -152
  220. package/templates/mls/src/pages/office_selection_page/office_selection_page.tsx +0 -144
  221. package/templates/mls/src/real_estate.type.ts +0 -44
  222. package/templates/mls/src/util/use_add_element.tsx +0 -62
  223. package/templates/mls/src/util/use_drag_element.tsx +0 -68
  224. package/templates/mls/styles/components.css +0 -38
  225. package/templates/mls/tsconfig.json +0 -54
  226. package/templates/mls/webpack.config.ts +0 -248
  227. package/templates/optional/.cursor/mcp.json +0 -8
  228. package/templates/optional/.vscode/extensions.json +0 -6
  229. package/templates/optional/.vscode/mcp.json +0 -9
  230. package/templates/optional/AGENTS.md +0 -154
  231. package/templates/optional/CLAUDE.md +0 -154
@@ -1,247 +0,0 @@
1
- import type { Configuration } from "webpack";
2
- import { DefinePlugin, optimize } from "webpack";
3
- import path from "path";
4
- import TerserPlugin from "terser-webpack-plugin";
5
- import { transform } from "@formatjs/ts-transformer";
6
- import chalk from "chalk";
7
- import { config } from "dotenv";
8
- import { Configuration as DevServerConfiguration } from "webpack-dev-server";
9
-
10
- config();
11
-
12
- type DevConfig = {
13
- port: number;
14
- enableHmr: boolean;
15
- enableHttps: boolean;
16
- appOrigin?: string;
17
- appId?: string; // Deprecated in favour of appOrigin
18
- certFile?: string;
19
- keyFile?: string;
20
- };
21
-
22
- export function buildConfig({
23
- devConfig,
24
- appEntry = path.join(process.cwd(), "src", "index.tsx"),
25
- backendHost = process.env.CANVA_BACKEND_HOST,
26
- // For IN_HARNESS, refer to the following docs for more information: https://www.canva.dev/docs/apps/test-harness/
27
- inHarness = process.env.IN_HARNESS?.toLowerCase() === "true",
28
- }: {
29
- devConfig?: DevConfig;
30
- appEntry?: string;
31
- backendHost?: string;
32
- inHarness?: boolean;
33
- } = {}): Configuration & DevServerConfiguration {
34
- const mode = devConfig ? "development" : "production";
35
-
36
- if (!backendHost) {
37
- console.warn(
38
- chalk.yellow.bold("BACKEND_HOST is undefined."),
39
- `If your app requires a backend, refer to "Customizing the backend host" in the README.md for more information.`,
40
- );
41
- } else if (backendHost.includes("localhost") && mode === "production") {
42
- console.error(
43
- chalk.redBright.bold(
44
- "BACKEND_HOST should not be set to localhost for production builds!",
45
- ),
46
- `Refer to "Customizing the backend host" in the README.md for more information.`,
47
- );
48
- }
49
-
50
- return {
51
- mode,
52
- context: path.resolve(process.cwd(), "./"),
53
- entry: inHarness
54
- ? {
55
- harness: path.join(process.cwd(), "harness", "harness.tsx"),
56
- init: path.join(process.cwd(), "harness", "init.ts"),
57
- }
58
- : {
59
- app: appEntry,
60
- },
61
- target: "web",
62
- resolve: {
63
- alias: {
64
- styles: path.resolve(process.cwd(), "styles"),
65
- src: path.resolve(process.cwd(), "src"),
66
- },
67
- extensions: [".ts", ".tsx", ".js", ".css", ".svg", ".woff", ".woff2"],
68
- },
69
- infrastructureLogging: {
70
- level: inHarness ? "info" : "none",
71
- },
72
- module: {
73
- rules: [
74
- {
75
- test: /\.tsx?$/,
76
- exclude: /node_modules/,
77
- use: [
78
- {
79
- loader: "ts-loader",
80
- options: {
81
- transpileOnly: true,
82
- getCustomTransformers() {
83
- return {
84
- before: [
85
- transform({
86
- overrideIdFn: "[sha512:contenthash:base64:6]",
87
- }),
88
- ],
89
- };
90
- },
91
- },
92
- },
93
- ],
94
- },
95
- {
96
- test: /\.css$/,
97
- exclude: /node_modules/,
98
- use: [
99
- "style-loader",
100
- {
101
- loader: "css-loader",
102
- options: {
103
- modules: true,
104
- },
105
- },
106
- {
107
- loader: "postcss-loader",
108
- options: {
109
- postcssOptions: {
110
- plugins: [require("cssnano")({ preset: "default" })],
111
- },
112
- },
113
- },
114
- ],
115
- },
116
- {
117
- test: /\.(png|jpg|jpeg)$/i,
118
- type: "asset/inline",
119
- },
120
- {
121
- test: /\.(woff|woff2)$/,
122
- type: "asset/inline",
123
- },
124
- {
125
- test: /\.svg$/,
126
- oneOf: [
127
- {
128
- issuer: /\.[jt]sx?$/,
129
- resourceQuery: /react/, // *.svg?react
130
- use: ["@svgr/webpack", "url-loader"],
131
- },
132
- {
133
- type: "asset/resource",
134
- parser: {
135
- dataUrlCondition: {
136
- maxSize: 200,
137
- },
138
- },
139
- },
140
- ],
141
- },
142
- {
143
- test: /\.css$/,
144
- include: /node_modules/,
145
- use: [
146
- "style-loader",
147
- "css-loader",
148
- {
149
- loader: "postcss-loader",
150
- options: {
151
- postcssOptions: {
152
- plugins: [require("cssnano")({ preset: "default" })],
153
- },
154
- },
155
- },
156
- ],
157
- },
158
- ],
159
- },
160
- optimization: {
161
- minimizer: [
162
- new TerserPlugin({
163
- terserOptions: {
164
- format: {
165
- // Turned on because emoji and regex is not minified properly using default
166
- // https://github.com/facebook/create-react-app/issues/2488
167
- ascii_only: true,
168
- },
169
- },
170
- }),
171
- ],
172
- },
173
- output: {
174
- filename: `[name].js`,
175
- path: path.resolve(process.cwd(), "dist"),
176
- clean: true,
177
- },
178
- plugins: [
179
- new DefinePlugin({
180
- BACKEND_HOST: JSON.stringify(backendHost),
181
- }),
182
- // Apps can only submit a single JS file via the Developer Portal
183
- new optimize.LimitChunkCountPlugin({ maxChunks: 1 }),
184
- ].filter(Boolean),
185
- ...buildDevConfig(devConfig),
186
- };
187
- }
188
-
189
- function buildDevConfig(options?: DevConfig): {
190
- devtool?: string;
191
- devServer?: DevServerConfiguration;
192
- } {
193
- if (!options) {
194
- return {};
195
- }
196
-
197
- const { port, enableHmr, appOrigin, enableHttps, certFile, keyFile } =
198
- options;
199
- const host = "localhost";
200
-
201
- let devServer: DevServerConfiguration = {
202
- server: enableHttps
203
- ? {
204
- type: "https",
205
- options: {
206
- cert: certFile,
207
- key: keyFile,
208
- },
209
- }
210
- : "http",
211
- host,
212
- allowedHosts: [host],
213
- historyApiFallback: {
214
- rewrites: [{ from: /^\/$/, to: "/app.js" }],
215
- },
216
- port,
217
- client: {
218
- logging: "verbose",
219
- },
220
- };
221
-
222
- if (enableHmr && appOrigin) {
223
- devServer = {
224
- ...devServer,
225
- allowedHosts: [host, new URL(appOrigin).hostname],
226
- headers: {
227
- "Access-Control-Allow-Origin": appOrigin,
228
- "Access-Control-Allow-Credentials": "true",
229
- "Access-Control-Allow-Private-Network": "true",
230
- },
231
- };
232
- } else {
233
- if (enableHmr && !appOrigin) {
234
- console.warn(
235
- "Attempted to enable Hot Module Replacement (HMR) without configuring App Origin... Disabling HMR.",
236
- );
237
- }
238
- devServer.webSocketServer = false;
239
- }
240
-
241
- return {
242
- devtool: "source-map",
243
- devServer,
244
- };
245
- }
246
-
247
- export default buildConfig;
@@ -1,84 +0,0 @@
1
- # Data Connector Template
2
-
3
- ## Overview
4
-
5
- This template provides a working example of a data connector app which uses the Canva Connect API as a data source. It demonstrates how to log in with OAuth and then fetch data from an external source, using Canva's API for listing Designs and Brand Templates. There are instructions below for how to configure your authentication settings to try it out.
6
-
7
- The template provides a list / detail interface for choosing a data source. The user would first select the data source they want to import from a list. Next, they configure the data source to select the desired query by applying search filters or sort criteria. The app turns their configured data source into an API request and then returns the data in a table format for use in a Canva Design.
8
-
9
- ## Best Practices
10
-
11
- This template captures best practices for improving user experience in your application.
12
-
13
- ### State Management
14
-
15
- In this template, we've set up state management using `React Context`. It's just one way to do it, not a strict rule. If your app gets more complicated, you might want to check out other options like `Redux` or `MobX`.
16
-
17
- ### Routing
18
-
19
- As your application evolves, you may find the need for routing to manage multiple views or pages. In this template, we've integrated React Router to illustrate how routing can facilitate seamless navigation between various components.
20
-
21
- ### App UI Kit
22
-
23
- The App UI Kit is a React-based component library designed for creating apps that emulate Canva's look and feel. We strongly recommend using the App UI Kit if you're planning to release an app to the public, because this makes it easier to comply with our [design guidelines](https://www.canva.dev/docs/apps/design-guidelines/).
24
-
25
- ### Data Sources
26
-
27
- A data source is a type of data that this connector can retrieve. It has:
28
-
29
- - properties that define the configuration for this source - e.g. search criteria, ordering conditions, selection filters
30
- - UI for how to edit this configuration
31
- - columns to display for each data item
32
- - logic for how to fetch the data from an external API
33
-
34
- The initial data sources for the Canva Connect API (Designs and Brand Templates) in this template are located in `src/api/data_sources/`.
35
-
36
- This template provides a `DataSourceHandler` class in `src/api/data_source.ts` as a suggested starting point for defining a reusable concept for a data source and convert API responses into data table outputs.
37
-
38
- ## Setup - Authentication
39
-
40
- This template is a working app that reads the [Canva Connect API](https://www.canva.dev/docs/connect/).
41
-
42
- To run it and authenticate with the Canva Connect API via OAuth you must first complete some authentication setup steps.
43
-
44
- ### 0. Set up an App
45
-
46
- - If not already handled by the Canva CLI, you need to create an app via the [Developer Portal](https://www.canva.com/developers/apps).
47
- - On the **Intents** page, enable the `Data Connector` intent.
48
-
49
- ### 1. Set up a Connect API Integration
50
-
51
- - Go to [Your Integrations](https://www.canva.com/developers/integrations/connect-api) and create a new integration
52
- - On the **Configuration** page, generate a client secret - you need the client ID and client secret in the app setup.
53
- - On the **Scopes** page, add the `designs:meta` and `brandtemplate:meta` read scopes
54
- - On the **Authentication** page, set `https://www.canva.com/apps/oauth/authorized` as an Authorized redirect
55
-
56
- ### 2. Set up OAuth for the app
57
-
58
- - Go to [Your Apps](https://www.canva.com/developers/apps) and open your data connector app.
59
- - On the **Authentication** page, add an OAuth 2.0 provider with the following settings:
60
- > Provider: `CanvaConnect`
61
- >
62
- > Client ID: `(generated in step 1)`
63
- >
64
- > Client secret: `(generated in step 1)`
65
- >
66
- > Credential transfer mode: `Headers (default)`
67
- >
68
- > Authorization server URL: `https://www.canva.com/api/oauth/authorize`
69
- >
70
- > Token exchange URL: `https://api.canva.com/rest/v1/oauth/token`
71
- >
72
- > Proof Key for Code Exchange (PKCE): `Enabled`
73
-
74
- ### 3. Run your app
75
-
76
- - Run `npm start` to run the app.
77
- - Click **Preview** in the [Developer Portal](https://www.canva.com/developers/apps) to view the app in the Canva editor.
78
- - You should be able to log in and then choose from the available data sources.
79
-
80
- ### To use another OAuth source
81
-
82
- - `src/api/oauth.ts` has a `scope` property that will be used in the oauth flow.
83
- - This template starts with the scope for the Canva Connect API login set to `["design:meta:read", "brandtemplate:meta:read"]`
84
- - It should match the scopes set in Step 1.
@@ -1,21 +0,0 @@
1
- {
2
- "$schema": "https://www.canva.dev/schemas/app/v1/manifest-schema.json",
3
- "manifest_schema_version": 1,
4
- "runtime": {
5
- "permissions": [
6
- {
7
- "name": "canva:design:content:read",
8
- "type": "mandatory"
9
- },
10
- {
11
- "name": "canva:design:content:write",
12
- "type": "mandatory"
13
- }
14
- ]
15
- },
16
- "intent": {
17
- "data_connector": {
18
- "enrolled": true
19
- }
20
- }
21
- }
@@ -1,29 +0,0 @@
1
- declare module "*.css" {
2
- const styles: { [className: string]: string };
3
- export = styles;
4
- }
5
-
6
- declare module "*.jpg" {
7
- const content: string;
8
- export default content;
9
- }
10
-
11
- declare module "*.jpeg" {
12
- const content: string;
13
- export default content;
14
- }
15
-
16
- declare module "*.png" {
17
- const content: string;
18
- export default content;
19
- }
20
-
21
- declare module "*.svg" {
22
- const content: React.FunctionComponent<{
23
- size?: "tiny" | "small" | "medium" | "large";
24
- className?: string;
25
- }>;
26
- export default content;
27
- }
28
-
29
- declare const BACKEND_HOST: string;
@@ -1,14 +0,0 @@
1
- import canvaPlugin from "@canva/app-eslint-plugin";
2
-
3
- export default [
4
- {
5
- ignores: [
6
- "**/node_modules/",
7
- "**/dist",
8
- "**/*.d.ts",
9
- "**/*.d.tsx",
10
- "**/*.config.*",
11
- ],
12
- },
13
- ...canvaPlugin.configs.apps,
14
- ];
@@ -1,92 +0,0 @@
1
- {
2
- "private": true,
3
- "name": "data_connector",
4
- "description": "An example Canva Data Connector App",
5
- "scripts": {
6
- "extract": "formatjs extract \"src/**/*.{ts,tsx}\" --out-file dist/messages_en.json",
7
- "build": "webpack --config webpack.config.ts --mode production && npm run extract",
8
- "format": "prettier '**/*.{css,ts,tsx}' --no-config --write",
9
- "format:check": "prettier '**/*.{css,ts,tsx}' --no-config --check --ignore-path",
10
- "format:file": "prettier $1 --no-config --write",
11
- "lint": "eslint .",
12
- "lint:fix": "eslint . --fix",
13
- "lint:types": "tsc",
14
- "start": "ts-node ./scripts/start/start.ts",
15
- "start:preview": "npm run start -- --preview",
16
- "test": "jest --no-cache",
17
- "test:watch": "jest --watchAll",
18
- "test:update": "npm run test -- -u",
19
- "postinstall": "ts-node ./scripts/copy_env.ts"
20
- },
21
- "dependencies": {
22
- "@canva/app-hooks": "^0.0.0-beta.4",
23
- "@canva/app-i18n-kit": "^1.2.0",
24
- "@canva/app-ui-kit": "^5.5.0",
25
- "@canva/asset": "^2.3.0",
26
- "@canva/design": "^2.8.0",
27
- "@canva/error": "^2.2.0",
28
- "@canva/intents": "^2.2.0",
29
- "@canva/platform": "^2.2.1",
30
- "@canva/user": "^2.1.2",
31
- "react": "^19.2.3",
32
- "react-dom": "^19.2.3",
33
- "react-error-boundary": "6.0.0",
34
- "react-intl": "^7.1.11",
35
- "react-router-dom": "7.12.0"
36
- },
37
- "devDependencies": {
38
- "@canva/app-eslint-plugin": "^1.0.0-beta.7",
39
- "@canva/cli": ">= 0.0.1-beta.13",
40
- "@formatjs/cli": "6.7.2",
41
- "@formatjs/ts-transformer": "3.14.0",
42
- "@ngrok/ngrok": "1.5.2",
43
- "@pmmmwh/react-refresh-webpack-plugin": "0.6.1",
44
- "@svgr/webpack": "8.1.0",
45
- "@testing-library/react": "16.3.0",
46
- "@types/debug": "4.1.12",
47
- "@types/express": "4.17.21",
48
- "@types/jest": "29.5.14",
49
- "@types/jsonwebtoken": "9.0.10",
50
- "@types/node": "20.19.2",
51
- "@types/node-fetch": "2.6.13",
52
- "@types/node-forge": "1.3.14",
53
- "@types/nodemon": "1.19.6",
54
- "@types/react": "19.2.2",
55
- "@types/react-dom": "19.2.1",
56
- "@types/webpack-env": "1.18.8",
57
- "chalk": "4.1.2",
58
- "cli-table3": "0.6.5",
59
- "css-loader": "7.1.2",
60
- "css-modules-typescript-loader": "4.0.1",
61
- "cssnano": "7.1.1",
62
- "debug": "4.4.1",
63
- "dotenv": "16.6.0",
64
- "express": "4.22.1",
65
- "express-basic-auth": "1.2.1",
66
- "jest": "29.7.0",
67
- "jest-css-modules-transform": "4.4.2",
68
- "jest-environment-jsdom": "29.7.0",
69
- "jsonwebtoken": "9.0.3",
70
- "jwks-rsa": "3.2.0",
71
- "mini-css-extract-plugin": "2.9.4",
72
- "node-fetch": "3.3.2",
73
- "node-forge": "1.3.2",
74
- "nodemon": "3.0.1",
75
- "open": "8.4.2",
76
- "postcss-loader": "8.1.1",
77
- "prettier": "3.6.2",
78
- "react-refresh": "0.17.0",
79
- "style-loader": "4.0.0",
80
- "terser-webpack-plugin": "5.3.14",
81
- "tree-kill": "1.2.2",
82
- "ts-jest": "29.4.1",
83
- "ts-loader": "9.5.4",
84
- "ts-node": "10.9.2",
85
- "typescript": "5.9.2",
86
- "url-loader": "4.1.1",
87
- "webpack": "5.99.9",
88
- "webpack-cli": "6.0.1",
89
- "webpack-dev-server": "5.2.2",
90
- "yargs": "17.7.2"
91
- }
92
- }
@@ -1,13 +0,0 @@
1
- #!/usr/bin/env node
2
- /* eslint-disable no-console */
3
- import fs from "fs";
4
- import path from "path";
5
-
6
- const envPath = path.resolve(__dirname, "..", ".env");
7
- const templatePath = path.resolve(__dirname, "..", ".env.template");
8
-
9
- if (!fs.existsSync(templatePath)) {
10
- console.warn(".env.template file does not exist, skipping copy of .env file");
11
- } else if (!fs.existsSync(envPath)) {
12
- fs.copyFileSync(templatePath, envPath);
13
- }
@@ -1,131 +0,0 @@
1
- import crypto from "crypto";
2
- import fs from "fs/promises";
3
- import { pki } from "node-forge";
4
- import path from "path";
5
-
6
- const SSL_CERT_DIR = path.resolve(process.cwd(), "..", "..", ".ssl");
7
- const CERT_FILE = path.resolve(SSL_CERT_DIR, "certificate.pem");
8
- const KEY_FILE = path.resolve(SSL_CERT_DIR, "private-key.pem");
9
-
10
- export interface Certificate {
11
- keyFile: string;
12
- certFile: string;
13
- }
14
-
15
- const CERT_ATTRS: { name: string; value: string }[] = [
16
- {
17
- name: "commonName",
18
- value: "localhost",
19
- },
20
- {
21
- name: "countryName",
22
- value: "AU",
23
- },
24
- {
25
- name: "stateOrProvinceName",
26
- value: "New South Wales",
27
- },
28
- {
29
- name: "localityName",
30
- value: "Sydney",
31
- },
32
- {
33
- name: "organizationName",
34
- value: "Test",
35
- },
36
- {
37
- name: "organizationalUnitName",
38
- value: "Test",
39
- },
40
- ];
41
-
42
- const generateRsaKeys = async (): Promise<{
43
- publicKey: string;
44
- privateKey: string;
45
- }> =>
46
- new Promise((resolve, reject) => {
47
- crypto.generateKeyPair(
48
- "rsa",
49
- {
50
- modulusLength: 2096,
51
- publicKeyEncoding: {
52
- type: "spki",
53
- format: "pem",
54
- },
55
- privateKeyEncoding: {
56
- type: "pkcs8",
57
- format: "pem",
58
- },
59
- },
60
- (err, publicKey, privateKey) => {
61
- if (err) {
62
- reject(err);
63
- } else {
64
- resolve({ publicKey, privateKey });
65
- }
66
- },
67
- );
68
- });
69
-
70
- const generateCertificate = (opts: {
71
- privateKey: string;
72
- publicKey: string;
73
- }): string => {
74
- const privateKey = pki.privateKeyFromPem(opts.privateKey);
75
- const publicKey = pki.publicKeyFromPem(opts.publicKey);
76
-
77
- const cert = pki.createCertificate();
78
-
79
- cert.publicKey = publicKey;
80
- cert.serialNumber = "01";
81
- cert.validity.notBefore = new Date();
82
- cert.validity.notAfter = new Date();
83
- cert.validity.notAfter.setFullYear(cert.validity.notBefore.getFullYear() + 1);
84
-
85
- cert.setSubject(CERT_ATTRS);
86
- cert.setIssuer(CERT_ATTRS);
87
-
88
- // the actual certificate signing
89
- cert.sign(privateKey);
90
-
91
- // now convert the Forge certificate to PEM format
92
- return pki.certificateToPem(cert);
93
- };
94
-
95
- const writeCertFiles = async (opts: {
96
- cert: string;
97
- privateKey: string;
98
- }): Promise<void> => {
99
- const { cert, privateKey } = opts;
100
-
101
- await fs.mkdir(SSL_CERT_DIR, { recursive: true });
102
- await Promise.all([
103
- fs.writeFile(CERT_FILE, cert, { encoding: "utf8" }),
104
- fs.writeFile(KEY_FILE, privateKey, { encoding: "utf8" }),
105
- ]);
106
- };
107
-
108
- const cerfFilesExist = async (): Promise<boolean> => {
109
- try {
110
- await Promise.all([
111
- fs.access(CERT_FILE, fs.constants.R_OK | fs.constants.W_OK),
112
- fs.access(KEY_FILE, fs.constants.R_OK | fs.constants.W_OK),
113
- ]);
114
- return true;
115
- } catch {
116
- return false;
117
- }
118
- };
119
-
120
- export const createOrRetrieveCertificate = async (): Promise<Certificate> => {
121
- if (!(await cerfFilesExist())) {
122
- const keys = await generateRsaKeys();
123
- const cert = generateCertificate(keys);
124
- await writeCertFiles({ cert, privateKey: keys.privateKey });
125
- }
126
-
127
- return {
128
- certFile: CERT_FILE,
129
- keyFile: KEY_FILE,
130
- };
131
- };