@canva/cli 0.0.1-beta.9 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +131 -31
- package/cli.js +841 -437
- package/lib/cjs/index.cjs +11 -0
- package/lib/esm/index.mjs +11 -0
- package/package.json +19 -4
- package/templates/base/backend/routers/auth.ts +4 -4
- package/templates/base/backend/routers/oauth.ts +3 -3
- package/templates/base/eslint.config.mjs +2 -25
- package/templates/base/package.json +26 -23
- package/templates/base/scripts/ssl/ssl.ts +1 -1
- package/templates/base/scripts/start/app_runner.ts +42 -5
- package/templates/base/scripts/start/context.ts +12 -6
- package/templates/base/scripts/start/start.ts +12 -1
- package/templates/base/scripts/start/tests/start.tests.ts +61 -0
- package/templates/base/utils/backend/base_backend/create.ts +3 -3
- package/templates/base/utils/backend/bearer_middleware/bearer_middleware.ts +2 -2
- package/templates/base/utils/backend/jwt_middleware/jwt_middleware.ts +4 -4
- package/templates/base/utils/backend/jwt_middleware/tests/jwt_middleware.tests.ts +1 -1
- package/templates/base/utils/use_add_element.ts +1 -1
- package/templates/base/utils/use_feature_support.ts +1 -1
- package/templates/{gen_ai/webpack.config.cjs → base/webpack.config.ts} +50 -68
- package/templates/common/.env.template +3 -3
- package/templates/common/README.md +16 -17
- package/templates/common/jest.config.mjs +1 -1
- package/templates/common/jest.setup.ts +1 -0
- package/templates/common/utils/backend/base_backend/create.ts +3 -3
- package/templates/common/utils/backend/jwt_middleware/jwt_middleware.ts +4 -4
- package/templates/common/utils/backend/jwt_middleware/tests/jwt_middleware.tests.ts +1 -1
- package/templates/common/utils/tests/table_wrapper.tests.ts +1 -1
- package/templates/common/utils/use_add_element.ts +1 -1
- package/templates/common/utils/use_feature_support.ts +1 -1
- package/templates/dam/backend/routers/dam.ts +24 -20
- package/templates/dam/backend/server.ts +1 -1
- package/templates/dam/canva-app.json +16 -0
- package/templates/dam/eslint.config.mjs +2 -28
- package/templates/dam/package.json +38 -41
- package/templates/dam/scripts/ssl/ssl.ts +1 -1
- package/templates/dam/scripts/start/app_runner.ts +42 -5
- package/templates/dam/scripts/start/context.ts +12 -6
- package/templates/dam/scripts/start/start.ts +12 -1
- package/templates/dam/scripts/start/tests/start.tests.ts +61 -0
- package/templates/dam/src/app.tsx +24 -3
- package/templates/dam/src/config.ts +212 -87
- package/templates/dam/src/index.tsx +1 -1
- package/templates/dam/utils/backend/base_backend/create.ts +3 -3
- package/templates/dam/utils/backend/jwt_middleware/jwt_middleware.ts +4 -4
- package/templates/dam/utils/backend/jwt_middleware/tests/jwt_middleware.tests.ts +1 -1
- package/templates/{base/webpack.config.cjs → dam/webpack.config.ts} +50 -68
- package/templates/data_connector/README.md +84 -0
- package/templates/data_connector/canva-app.json +21 -0
- package/templates/data_connector/declarations/declarations.d.ts +29 -0
- package/templates/data_connector/eslint.config.mjs +14 -0
- package/templates/data_connector/package.json +91 -0
- package/templates/data_connector/scripts/ssl/ssl.ts +131 -0
- package/templates/data_connector/scripts/start/app_runner.ts +201 -0
- package/templates/data_connector/scripts/start/context.ts +171 -0
- package/templates/data_connector/scripts/start/start.ts +46 -0
- package/templates/data_connector/scripts/start/tests/start.tests.ts +61 -0
- package/templates/data_connector/src/api/connect_client.ts +6 -0
- package/templates/data_connector/src/api/data_source.ts +96 -0
- package/templates/data_connector/src/api/data_sources/designs.tsx +296 -0
- package/templates/data_connector/src/api/data_sources/index.ts +4 -0
- package/templates/data_connector/src/api/data_sources/templates.tsx +329 -0
- package/templates/data_connector/src/api/fetch_data_table.ts +55 -0
- package/templates/data_connector/src/api/index.ts +4 -0
- package/templates/data_connector/src/api/oauth.ts +8 -0
- package/templates/data_connector/src/api/tests/data_source.test.tsx +99 -0
- package/templates/data_connector/src/app.tsx +20 -0
- package/templates/data_connector/src/components/app_error.tsx +15 -0
- package/templates/data_connector/src/components/footer.tsx +26 -0
- package/templates/data_connector/src/components/header.tsx +40 -0
- package/templates/data_connector/src/components/index.ts +3 -0
- package/templates/data_connector/src/components/inputs/messages.tsx +99 -0
- package/templates/data_connector/src/components/inputs/search_filter.tsx +108 -0
- package/templates/data_connector/src/components/inputs/select_field.tsx +26 -0
- package/templates/data_connector/src/context/app_context.tsx +124 -0
- package/templates/data_connector/src/context/index.ts +2 -0
- package/templates/data_connector/src/context/use_app_context.ts +17 -0
- package/templates/data_connector/src/entrypoint.tsx +70 -0
- package/templates/data_connector/src/home.tsx +21 -0
- package/templates/data_connector/src/index.tsx +68 -0
- package/templates/data_connector/src/pages/data_source_config.tsx +9 -0
- package/templates/data_connector/src/pages/error.tsx +37 -0
- package/templates/data_connector/src/pages/index.ts +4 -0
- package/templates/data_connector/src/pages/login.tsx +145 -0
- package/templates/data_connector/src/pages/select_source.tsx +24 -0
- package/templates/data_connector/src/routes/index.ts +2 -0
- package/templates/data_connector/src/routes/protected_route.tsx +25 -0
- package/templates/data_connector/src/routes/routes.tsx +46 -0
- package/templates/data_connector/src/utils/data_params.ts +17 -0
- package/templates/data_connector/src/utils/data_table.ts +115 -0
- package/templates/data_connector/src/utils/fetch_result.ts +36 -0
- package/templates/data_connector/src/utils/index.ts +2 -0
- package/templates/data_connector/src/utils/tests/data_table.test.ts +133 -0
- package/templates/data_connector/styles/components.css +38 -0
- package/templates/data_connector/tsconfig.json +54 -0
- package/templates/{dam/webpack.config.cjs → data_connector/webpack.config.ts} +50 -68
- package/templates/gen_ai/backend/routers/image.ts +8 -8
- package/templates/gen_ai/backend/server.ts +1 -1
- package/templates/gen_ai/canva-app.json +20 -0
- package/templates/gen_ai/eslint.config.mjs +2 -25
- package/templates/gen_ai/package.json +42 -43
- package/templates/gen_ai/scripts/ssl/ssl.ts +1 -1
- package/templates/gen_ai/scripts/start/app_runner.ts +42 -5
- package/templates/gen_ai/scripts/start/context.ts +12 -6
- package/templates/gen_ai/scripts/start/start.ts +12 -1
- package/templates/gen_ai/scripts/start/tests/start.tests.ts +61 -0
- package/templates/gen_ai/src/app.tsx +3 -3
- package/templates/gen_ai/src/components/footer.tsx +4 -4
- package/templates/gen_ai/src/components/image_grid.tsx +1 -1
- package/templates/gen_ai/src/components/loading_results.tsx +8 -8
- package/templates/gen_ai/src/components/prompt_input.tsx +3 -3
- package/templates/gen_ai/src/components/remaining_credits.tsx +1 -1
- package/templates/gen_ai/src/components/report_box.tsx +1 -1
- package/templates/gen_ai/src/components/tests/remaining_credit.tests.tsx +2 -2
- package/templates/gen_ai/src/home.tsx +2 -2
- package/templates/gen_ai/src/pages/error.tsx +2 -2
- package/templates/gen_ai/src/pages/results.tsx +1 -1
- package/templates/gen_ai/utils/backend/base_backend/create.ts +3 -3
- package/templates/gen_ai/utils/backend/bearer_middleware/bearer_middleware.ts +2 -2
- package/templates/{hello_world/webpack.config.cjs → gen_ai/webpack.config.ts} +50 -68
- package/templates/hello_world/canva-app.json +16 -0
- package/templates/hello_world/eslint.config.mjs +2 -25
- package/templates/hello_world/package.json +35 -38
- package/templates/hello_world/scripts/copy_env.ts +10 -0
- package/templates/hello_world/scripts/ssl/ssl.ts +1 -1
- package/templates/hello_world/scripts/start/app_runner.ts +42 -5
- package/templates/hello_world/scripts/start/context.ts +12 -6
- package/templates/hello_world/scripts/start/start.ts +12 -1
- package/templates/hello_world/scripts/start/tests/start.tests.ts +61 -0
- package/templates/hello_world/src/app.tsx +1 -1
- package/templates/hello_world/src/index.tsx +1 -1
- package/templates/hello_world/src/tests/__snapshots__/app.tests.tsx.snap +5 -5
- package/templates/hello_world/src/tests/app.tests.tsx +3 -3
- package/templates/hello_world/utils/use_add_element.ts +1 -1
- package/templates/hello_world/utils/use_feature_support.ts +1 -1
- package/templates/hello_world/webpack.config.ts +254 -0
- package/templates/optional/.cursor/mcp.json +8 -0
- package/templates/optional/.vscode/mcp.json +9 -0
- package/templates/optional/AGENTS.md +76 -0
- package/templates/optional/CLAUDE.md +76 -0
- package/templates/common/conf/eslint-general.mjs +0 -303
- package/templates/common/conf/eslint-i18n.mjs +0 -41
- package/templates/common/conf/eslint-local-i18n-rules/index.mjs +0 -181
- /package/templates/base/scripts/{copy-env.ts → copy_env.ts} +0 -0
- /package/templates/dam/scripts/{copy-env.ts → copy_env.ts} +0 -0
- /package/templates/{gen_ai/scripts/copy-env.ts → data_connector/scripts/copy_env.ts} +0 -0
- /package/templates/{hello_world/scripts/copy-env.ts → gen_ai/scripts/copy_env.ts} +0 -0
- /package/templates/{common → optional}/.vscode/extensions.json +0 -0
|
@@ -1,95 +1,220 @@
|
|
|
1
1
|
import type { Config } from "@canva/app-components";
|
|
2
|
+
import { useIntl } from "react-intl";
|
|
2
3
|
|
|
3
4
|
type ContainerTypes = "folder";
|
|
4
|
-
export const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
value: "
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
5
|
+
export const useConfig = (): Config<ContainerTypes> => {
|
|
6
|
+
const intl = useIntl();
|
|
7
|
+
return {
|
|
8
|
+
serviceName: intl.formatMessage({
|
|
9
|
+
defaultMessage: "Example App",
|
|
10
|
+
description:
|
|
11
|
+
"Name of the service where the app will pull digital assets from",
|
|
12
|
+
}),
|
|
13
|
+
search: {
|
|
14
|
+
enabled: true,
|
|
15
|
+
filterFormConfig: {
|
|
16
|
+
containerTypes: ["folder"],
|
|
17
|
+
filters: [
|
|
18
|
+
{
|
|
19
|
+
filterType: "CHECKBOX",
|
|
20
|
+
label: intl.formatMessage({
|
|
21
|
+
defaultMessage: "File Type",
|
|
22
|
+
description: "Label of filters for file type",
|
|
23
|
+
}),
|
|
24
|
+
key: "fileType",
|
|
25
|
+
// These options do not need to be translated as they are universal technical terms
|
|
26
|
+
/* eslint-disable formatjs/no-literal-string-in-object */
|
|
27
|
+
options: [
|
|
28
|
+
{ value: "mp4", label: "MP4" },
|
|
29
|
+
{ value: "png", label: "PNG" },
|
|
30
|
+
{ value: "jpeg", label: "JPEG" },
|
|
31
|
+
],
|
|
32
|
+
/* eslint-enable formatjs/no-literal-string-in-object */
|
|
33
|
+
allowCustomValue: true,
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
filterType: "RADIO",
|
|
37
|
+
label: intl.formatMessage({
|
|
38
|
+
defaultMessage: "Size",
|
|
39
|
+
description: "Label of filters for asset size",
|
|
40
|
+
}),
|
|
41
|
+
key: "size",
|
|
42
|
+
options: [
|
|
43
|
+
{
|
|
44
|
+
label: intl.formatMessage({
|
|
45
|
+
defaultMessage: "Large (800+ px)",
|
|
46
|
+
description: "One of the filter options for asset size",
|
|
47
|
+
}),
|
|
48
|
+
value: "large",
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
label: intl.formatMessage({
|
|
52
|
+
defaultMessage: "Medium (200-799px)",
|
|
53
|
+
description: "One of the filter options for asset size",
|
|
54
|
+
}),
|
|
55
|
+
value: "medium",
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
allowCustomValue: true,
|
|
59
|
+
customValueInputType: "SIZE_RANGE",
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
filterType: "RADIO",
|
|
63
|
+
label: intl.formatMessage({
|
|
64
|
+
defaultMessage: "Update Date",
|
|
65
|
+
description: "Label of the filters for asset's update date",
|
|
66
|
+
}),
|
|
67
|
+
key: "updateDate",
|
|
68
|
+
options: [
|
|
69
|
+
{
|
|
70
|
+
value: ">now-30m",
|
|
71
|
+
label: intl.formatMessage({
|
|
72
|
+
defaultMessage: "Last 30 Minutes",
|
|
73
|
+
description:
|
|
74
|
+
"One of the filter options for asset update date",
|
|
75
|
+
}),
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
value: ">now-7d",
|
|
79
|
+
label: intl.formatMessage({
|
|
80
|
+
defaultMessage: "Last 7 days",
|
|
81
|
+
description:
|
|
82
|
+
"One of the filter options for asset update date",
|
|
83
|
+
}),
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
allowCustomValue: true,
|
|
87
|
+
customValueInputType: "DATE_RANGE",
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
filterType: "RADIO",
|
|
91
|
+
label: intl.formatMessage({
|
|
92
|
+
defaultMessage: "Design Status",
|
|
93
|
+
description: "Label of the filters for asset's design status",
|
|
94
|
+
}),
|
|
95
|
+
key: "designStatus",
|
|
96
|
+
options: [
|
|
97
|
+
{
|
|
98
|
+
value: "approved",
|
|
99
|
+
label: intl.formatMessage({
|
|
100
|
+
defaultMessage: "Approved",
|
|
101
|
+
description:
|
|
102
|
+
"One of the filter options for asset design status",
|
|
103
|
+
}),
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
value: "rejected",
|
|
107
|
+
label: intl.formatMessage({
|
|
108
|
+
defaultMessage: "Rejected",
|
|
109
|
+
description:
|
|
110
|
+
"One of the filter options for asset design status",
|
|
111
|
+
}),
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
value: "draft",
|
|
115
|
+
label: intl.formatMessage({
|
|
116
|
+
defaultMessage: "Draft",
|
|
117
|
+
description:
|
|
118
|
+
"One of the filter options for asset design status",
|
|
119
|
+
}),
|
|
120
|
+
},
|
|
121
|
+
],
|
|
122
|
+
allowCustomValue: true,
|
|
123
|
+
customValueInputType: "PLAIN_TEXT",
|
|
124
|
+
},
|
|
125
|
+
],
|
|
126
|
+
},
|
|
63
127
|
},
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
surface: "
|
|
73
|
-
|
|
128
|
+
containerTypes: [
|
|
129
|
+
{
|
|
130
|
+
value: "folder",
|
|
131
|
+
label: intl.formatMessage({
|
|
132
|
+
defaultMessage: "Folders",
|
|
133
|
+
description: "Name of the asset container type",
|
|
134
|
+
}),
|
|
135
|
+
listingSurfaces: [
|
|
136
|
+
{ surface: "HOMEPAGE" },
|
|
137
|
+
{
|
|
138
|
+
surface: "CONTAINER",
|
|
139
|
+
parentContainerTypes: ["folder"],
|
|
140
|
+
},
|
|
141
|
+
{ surface: "SEARCH" },
|
|
142
|
+
],
|
|
143
|
+
searchInsideContainer: {
|
|
144
|
+
enabled: true,
|
|
145
|
+
placeholder: intl.formatMessage({
|
|
146
|
+
defaultMessage: "Search for media inside this folder",
|
|
147
|
+
description: "Placeholder of a search input box",
|
|
148
|
+
}),
|
|
74
149
|
},
|
|
75
|
-
{ surface: "SEARCH" },
|
|
76
|
-
],
|
|
77
|
-
searchInsideContainer: {
|
|
78
|
-
enabled: true,
|
|
79
|
-
placeholder: "Search for resources inside this folder",
|
|
80
150
|
},
|
|
151
|
+
],
|
|
152
|
+
sortOptions: [
|
|
153
|
+
{
|
|
154
|
+
value: "created_at DESC",
|
|
155
|
+
label: intl.formatMessage({
|
|
156
|
+
defaultMessage: "Creation date (newest)",
|
|
157
|
+
description: "One of the sort options",
|
|
158
|
+
}),
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
value: "created_at ASC",
|
|
162
|
+
label: intl.formatMessage({
|
|
163
|
+
defaultMessage: "Creation date (oldest)",
|
|
164
|
+
description: "One of the sort options",
|
|
165
|
+
}),
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
value: "updated_at DESC",
|
|
169
|
+
label: intl.formatMessage({
|
|
170
|
+
defaultMessage: "Updated (newest)",
|
|
171
|
+
description: "One of the sort options",
|
|
172
|
+
}),
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
value: "updated_at ASC",
|
|
176
|
+
label: intl.formatMessage({
|
|
177
|
+
defaultMessage: "Updated (oldest)",
|
|
178
|
+
description: "One of the sort options",
|
|
179
|
+
}),
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
value: "name ASC",
|
|
183
|
+
label: intl.formatMessage({
|
|
184
|
+
defaultMessage: "Name (A-Z)",
|
|
185
|
+
description: "One of the sort options",
|
|
186
|
+
}),
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
value: "name DESC",
|
|
190
|
+
label: intl.formatMessage({
|
|
191
|
+
defaultMessage: "Name (Z-A)",
|
|
192
|
+
description: "One of the sort options",
|
|
193
|
+
}),
|
|
194
|
+
},
|
|
195
|
+
],
|
|
196
|
+
layouts: ["MASONRY", "LIST"],
|
|
197
|
+
resourceTypes: ["IMAGE", "VIDEO", "EMBED"],
|
|
198
|
+
moreInfoMessage: intl.formatMessage({
|
|
199
|
+
defaultMessage:
|
|
200
|
+
"At the moment, we only support images and videos. Corrupted and unsupported files will not appear.",
|
|
201
|
+
description: "Helper text to explain why some assets are not visible",
|
|
202
|
+
}),
|
|
203
|
+
// TODO remove `export` if your app does not support exporting the Canva design into an external platform
|
|
204
|
+
export: {
|
|
205
|
+
enabled: true,
|
|
206
|
+
// TODO provide a container type that user can choose to save into, or remove this field if user doesn't need to choose a container
|
|
207
|
+
containerTypes: ["folder"],
|
|
208
|
+
// TODO remove file types that are not supported by your platform
|
|
209
|
+
acceptedFileTypes: [
|
|
210
|
+
"png",
|
|
211
|
+
"pdf_standard",
|
|
212
|
+
"jpg",
|
|
213
|
+
"gif",
|
|
214
|
+
"svg",
|
|
215
|
+
"video",
|
|
216
|
+
"pptx",
|
|
217
|
+
],
|
|
81
218
|
},
|
|
82
|
-
|
|
83
|
-
sortOptions: [
|
|
84
|
-
{ value: "created_at DESC", label: "Creation date (newest)" },
|
|
85
|
-
{ value: "created_at ASC", label: "Creation date (oldest)" },
|
|
86
|
-
{ value: "updated_at DESC", label: "Updated (newest)" },
|
|
87
|
-
{ value: "updated_at ASC", label: "Updated (oldest)" },
|
|
88
|
-
{ value: "name ASC", label: "Name (A-Z)" },
|
|
89
|
-
{ value: "name DESC", label: "Name (Z-A)" },
|
|
90
|
-
],
|
|
91
|
-
layouts: ["MASONRY", "LIST"],
|
|
92
|
-
resourceTypes: ["IMAGE", "VIDEO", "EMBED"],
|
|
93
|
-
moreInfoMessage:
|
|
94
|
-
"At the moment, we only support images and videos. Corrupted and unsupported files will not appear.",
|
|
219
|
+
};
|
|
95
220
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { AppI18nProvider } from "@canva/app-i18n-kit";
|
|
1
2
|
import { AppUiProvider } from "@canva/app-ui-kit";
|
|
2
3
|
import { createRoot } from "react-dom/client";
|
|
3
4
|
import { App } from "./app";
|
|
4
5
|
import "@canva/app-ui-kit/styles.css";
|
|
5
|
-
import { AppI18nProvider } from "@canva/app-i18n-kit";
|
|
6
6
|
|
|
7
7
|
const root = createRoot(document.getElementById("root") as Element);
|
|
8
8
|
function render() {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/* eslint-disable no-console */
|
|
2
|
+
import debug from "debug";
|
|
2
3
|
import * as express from "express";
|
|
4
|
+
import type { NextFunction, Request, Response } from "express";
|
|
5
|
+
import * as fs from "fs";
|
|
3
6
|
import * as http from "http";
|
|
4
7
|
import * as https from "https";
|
|
5
|
-
import * as fs from "fs";
|
|
6
|
-
import type { Request, Response, NextFunction } from "express";
|
|
7
|
-
import debug from "debug";
|
|
8
8
|
|
|
9
9
|
const serverDebug = debug("server");
|
|
10
10
|
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/* eslint-disable no-console */
|
|
2
2
|
import * as chalk from "chalk";
|
|
3
3
|
import * as debug from "debug";
|
|
4
|
-
import type { Request, Response
|
|
5
|
-
import * as jwt from "jsonwebtoken";
|
|
6
|
-
import { JwksClient, SigningKeyNotFoundError } from "jwks-rsa";
|
|
4
|
+
import type { NextFunction, Request, Response } from "express";
|
|
7
5
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
8
6
|
import Express from "express-serve-static-core";
|
|
7
|
+
import * as jwt from "jsonwebtoken";
|
|
8
|
+
import { JwksClient, SigningKeyNotFoundError } from "jwks-rsa";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Prefix your start command with `DEBUG=express:middleware:jwt` to enable debug logging
|
|
@@ -110,7 +110,7 @@ export function createJwtMiddleware(
|
|
|
110
110
|
return sendUnauthorizedResponse(res);
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
-
req
|
|
113
|
+
req["canva"] = {
|
|
114
114
|
appId: payload.aud,
|
|
115
115
|
brandId: payload.brandId,
|
|
116
116
|
userId: payload.userId,
|
|
@@ -446,7 +446,7 @@ describe("createJwtMiddleware", () => {
|
|
|
446
446
|
expect(res.status).not.toHaveBeenCalled();
|
|
447
447
|
expect(res.json).not.toHaveBeenCalled();
|
|
448
448
|
|
|
449
|
-
expect(req
|
|
449
|
+
expect(req["canva"]).toEqual({
|
|
450
450
|
userId: FAKE_USER_ID,
|
|
451
451
|
brandId: FAKE_BRAND_ID,
|
|
452
452
|
appId: FAKE_APP_ID,
|
|
@@ -1,31 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import type { Configuration } from "webpack";
|
|
2
|
+
import { DefinePlugin, optimize } from "webpack";
|
|
3
|
+
import * as path from "path";
|
|
4
|
+
import * as TerserPlugin from "terser-webpack-plugin";
|
|
5
|
+
import { transform } from "@formatjs/ts-transformer";
|
|
6
|
+
import * as chalk from "chalk";
|
|
7
|
+
import { config } from "dotenv";
|
|
8
|
+
import { Configuration as DevServerConfiguration } from "webpack-dev-server";
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
* @returns {Object}
|
|
23
|
-
*/
|
|
24
|
-
function buildConfig({
|
|
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({
|
|
25
23
|
devConfig,
|
|
26
24
|
appEntry = path.join(process.cwd(), "src", "index.tsx"),
|
|
27
25
|
backendHost = process.env.CANVA_BACKEND_HOST,
|
|
28
|
-
|
|
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 {
|
|
29
34
|
const mode = devConfig ? "development" : "production";
|
|
30
35
|
|
|
31
36
|
if (!backendHost) {
|
|
@@ -46,9 +51,14 @@ function buildConfig({
|
|
|
46
51
|
return {
|
|
47
52
|
mode,
|
|
48
53
|
context: path.resolve(process.cwd(), "./"),
|
|
49
|
-
entry:
|
|
50
|
-
|
|
51
|
-
|
|
54
|
+
entry: inHarness
|
|
55
|
+
? {
|
|
56
|
+
harness: path.join(process.cwd(), "harness", "harness.tsx"),
|
|
57
|
+
init: path.join(process.cwd(), "harness", "init.ts"),
|
|
58
|
+
}
|
|
59
|
+
: {
|
|
60
|
+
app: appEntry,
|
|
61
|
+
},
|
|
52
62
|
target: "web",
|
|
53
63
|
resolve: {
|
|
54
64
|
alias: {
|
|
@@ -60,7 +70,7 @@ function buildConfig({
|
|
|
60
70
|
extensions: [".ts", ".tsx", ".js", ".css", ".svg", ".woff", ".woff2"],
|
|
61
71
|
},
|
|
62
72
|
infrastructureLogging: {
|
|
63
|
-
level: "none",
|
|
73
|
+
level: inHarness ? "info" : "none",
|
|
64
74
|
},
|
|
65
75
|
module: {
|
|
66
76
|
rules: [
|
|
@@ -172,35 +182,26 @@ function buildConfig({
|
|
|
172
182
|
new DefinePlugin({
|
|
173
183
|
BACKEND_HOST: JSON.stringify(backendHost),
|
|
174
184
|
}),
|
|
175
|
-
// Apps can only submit a single JS file via the
|
|
185
|
+
// Apps can only submit a single JS file via the Developer Portal
|
|
176
186
|
new optimize.LimitChunkCountPlugin({ maxChunks: 1 }),
|
|
177
|
-
mode === "development" && new ReactRefreshWebpackPlugin(),
|
|
178
187
|
].filter(Boolean),
|
|
179
188
|
...buildDevConfig(devConfig),
|
|
180
189
|
};
|
|
181
190
|
}
|
|
182
191
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
* @param {boolean} [options.enableHmr]
|
|
188
|
-
* @param {boolean} [options.enableHttps]
|
|
189
|
-
* @param {string} [options.appOrigin]
|
|
190
|
-
* @param {string} [options.appId] - Deprecated in favour of appOrigin
|
|
191
|
-
* @param {string} [options.certFile]
|
|
192
|
-
* @param {string} [options.keyFile]
|
|
193
|
-
* @returns {Object|null}
|
|
194
|
-
*/
|
|
195
|
-
function buildDevConfig(options) {
|
|
192
|
+
function buildDevConfig(options?: DevConfig): {
|
|
193
|
+
devtool?: string;
|
|
194
|
+
devServer?: DevServerConfiguration;
|
|
195
|
+
} {
|
|
196
196
|
if (!options) {
|
|
197
|
-
return
|
|
197
|
+
return {};
|
|
198
198
|
}
|
|
199
199
|
|
|
200
200
|
const { port, enableHmr, appOrigin, appId, enableHttps, certFile, keyFile } =
|
|
201
201
|
options;
|
|
202
|
+
const host = "localhost";
|
|
202
203
|
|
|
203
|
-
let devServer = {
|
|
204
|
+
let devServer: DevServerConfiguration = {
|
|
204
205
|
server: enableHttps
|
|
205
206
|
? {
|
|
206
207
|
type: "https",
|
|
@@ -210,7 +211,8 @@ function buildDevConfig(options) {
|
|
|
210
211
|
},
|
|
211
212
|
}
|
|
212
213
|
: "http",
|
|
213
|
-
host
|
|
214
|
+
host,
|
|
215
|
+
allowedHosts: [host],
|
|
214
216
|
historyApiFallback: {
|
|
215
217
|
rewrites: [{ from: /^\/$/, to: "/app.js" }],
|
|
216
218
|
},
|
|
@@ -227,31 +229,13 @@ function buildDevConfig(options) {
|
|
|
227
229
|
if (enableHmr && appOrigin) {
|
|
228
230
|
devServer = {
|
|
229
231
|
...devServer,
|
|
230
|
-
allowedHosts: new URL(appOrigin).hostname,
|
|
232
|
+
allowedHosts: [host, new URL(appOrigin).hostname],
|
|
231
233
|
headers: {
|
|
232
234
|
"Access-Control-Allow-Origin": appOrigin,
|
|
233
235
|
"Access-Control-Allow-Credentials": "true",
|
|
234
236
|
"Access-Control-Allow-Private-Network": "true",
|
|
235
237
|
},
|
|
236
238
|
};
|
|
237
|
-
} else if (enableHmr && appId) {
|
|
238
|
-
// Deprecated - App ID should not be used to configure HMR in the future and can be safely removed
|
|
239
|
-
// after a few months.
|
|
240
|
-
|
|
241
|
-
console.warn(
|
|
242
|
-
"Enabling Hot Module Replacement (HMR) with an App ID is deprecated, please see the README.md on how to update.",
|
|
243
|
-
);
|
|
244
|
-
|
|
245
|
-
const appDomain = `app-${appId.toLowerCase().trim()}.canva-apps.com`;
|
|
246
|
-
devServer = {
|
|
247
|
-
...devServer,
|
|
248
|
-
allowedHosts: appDomain,
|
|
249
|
-
headers: {
|
|
250
|
-
"Access-Control-Allow-Origin": `https://${appDomain}`,
|
|
251
|
-
"Access-Control-Allow-Credentials": "true",
|
|
252
|
-
"Access-Control-Allow-Private-Network": "true",
|
|
253
|
-
},
|
|
254
|
-
};
|
|
255
239
|
} else {
|
|
256
240
|
if (enableHmr && !appOrigin) {
|
|
257
241
|
console.warn(
|
|
@@ -267,6 +251,4 @@ function buildDevConfig(options) {
|
|
|
267
251
|
};
|
|
268
252
|
}
|
|
269
253
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
module.exports.buildConfig = buildConfig;
|
|
254
|
+
export default buildConfig;
|
|
@@ -0,0 +1,84 @@
|
|
|
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.
|
|
47
|
+
Go to [Your Apps](https://www.canva.com/developers/apps) and create an app.
|
|
48
|
+
- On the **Configuration** page, enable the `Data Connector` intent.
|
|
49
|
+
|
|
50
|
+
### 1. Set up a Connect API Integration
|
|
51
|
+
|
|
52
|
+
- Go to [Your Integrations](https://www.canva.com/developers/integrations/connect-api) and create a new integration
|
|
53
|
+
- On the **Configuration** page, generate a client secret - you need the client ID and client secret in the app setup.
|
|
54
|
+
- On the **Scopes** page, add the `designs:meta` and `brandtemplate:meta` read scopes
|
|
55
|
+
- On the **Authentication** page, set `https://www.canva.com/apps/oauth/authorized` as an Authorized redirect
|
|
56
|
+
|
|
57
|
+
### 2. Set up OAuth for the app
|
|
58
|
+
|
|
59
|
+
- Go to [Your Apps](https://www.canva.com/developers/apps) and open your data connector app.
|
|
60
|
+
- On the **Authentication** page, add an OAuth 2.0 provider with the following settings:
|
|
61
|
+
> Provider: `CanvaConnect`
|
|
62
|
+
>
|
|
63
|
+
> Client ID: `(generated in step 1)`
|
|
64
|
+
>
|
|
65
|
+
> Client secret: `(generated in step 1)`
|
|
66
|
+
>
|
|
67
|
+
> Credential transfer mode: `Headers (default)`
|
|
68
|
+
>
|
|
69
|
+
> Authorization server URL: `https://www.canva.com/api/oauth/authorize`
|
|
70
|
+
>
|
|
71
|
+
> Token exchange URL: `https://api.canva.com/rest/v1/oauth/token`
|
|
72
|
+
>
|
|
73
|
+
> Proof Key for Code Exchange (PKCE): `Enabled`
|
|
74
|
+
|
|
75
|
+
### 3. Run your app
|
|
76
|
+
|
|
77
|
+
- Run `npm start` to run the app.
|
|
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.
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
}
|