@canva/cli 0.0.1-beta.8 → 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 +852 -427
- 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 +29 -26
- 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/{dam/webpack.config.cjs → base/webpack.config.ts} +51 -67
- package/templates/common/.env.template +3 -3
- package/templates/common/README.md +16 -17
- package/templates/common/jest.config.mjs +29 -2
- package/templates/common/jest.setup.ts +20 -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 +43 -40
- 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} +51 -67
- 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/{gen_ai/webpack.config.cjs → data_connector/webpack.config.ts} +51 -67
- 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 +47 -42
- 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 +16 -10
- 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 +43 -0
- package/templates/gen_ai/src/home.tsx +13 -0
- package/templates/gen_ai/src/index.tsx +2 -18
- package/templates/gen_ai/src/pages/error.tsx +2 -2
- package/templates/gen_ai/src/pages/results.tsx +1 -1
- package/templates/gen_ai/src/routes/routes.tsx +2 -2
- 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} +51 -67
- package/templates/hello_world/canva-app.json +16 -0
- package/templates/hello_world/eslint.config.mjs +2 -25
- package/templates/hello_world/package.json +42 -37
- 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 +21 -1
- package/templates/hello_world/src/index.tsx +1 -1
- package/templates/hello_world/src/tests/__snapshots__/app.tests.tsx.snap +45 -0
- package/templates/hello_world/src/tests/app.tests.tsx +86 -0
- 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 -38
- /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
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
|
|
3
|
+
import type { ChildProcess } from "child_process";
|
|
4
|
+
import { spawn } from "child_process";
|
|
5
|
+
import * as treeKill from "tree-kill";
|
|
6
|
+
|
|
7
|
+
describe("start script", () => {
|
|
8
|
+
let serverProcess: ChildProcess;
|
|
9
|
+
|
|
10
|
+
afterEach(() => {
|
|
11
|
+
if (serverProcess?.pid && !serverProcess.exitCode) {
|
|
12
|
+
treeKill(serverProcess.pid);
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("should execute 'npm run start' and start a dev server", async () => {
|
|
17
|
+
const testServerPort = 8089;
|
|
18
|
+
serverProcess = await spawn(
|
|
19
|
+
`npm run start -- -p ${testServerPort} --no-preview`,
|
|
20
|
+
{
|
|
21
|
+
shell: true,
|
|
22
|
+
},
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
if (!serverProcess.pid) {
|
|
26
|
+
throw new Error("Unable to start server");
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// wait for the server to start and collect output until it reports the running URL
|
|
30
|
+
let output = "";
|
|
31
|
+
await new Promise<void>((resolve, reject) => {
|
|
32
|
+
serverProcess.stdout?.on("data", (data) => {
|
|
33
|
+
output += data.toString();
|
|
34
|
+
if (output.includes("Development URL")) {
|
|
35
|
+
resolve();
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
serverProcess.stderr?.on("data", (data) => {
|
|
40
|
+
console.error("Server process error: ", data.toString());
|
|
41
|
+
reject();
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// timeout and fail test if the server hasn't correctly started in 10 seconds
|
|
45
|
+
setTimeout(() => {
|
|
46
|
+
if (serverProcess?.pid && !serverProcess.exitCode) {
|
|
47
|
+
treeKill(serverProcess.pid);
|
|
48
|
+
}
|
|
49
|
+
reject(new Error("Test timed out"));
|
|
50
|
+
}, 10000);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
// check that the server is running and accessible
|
|
54
|
+
const expectedServerURL = `http://localhost:${testServerPort}`;
|
|
55
|
+
expect(output).toContain(expectedServerURL);
|
|
56
|
+
expect(serverProcess.exitCode).toBeNull();
|
|
57
|
+
|
|
58
|
+
// clean up
|
|
59
|
+
treeKill(serverProcess.pid);
|
|
60
|
+
}, 15000); // 15 seconds timeout to allow for the server to start
|
|
61
|
+
});
|
|
@@ -1,14 +1,35 @@
|
|
|
1
1
|
import { SearchableListView } from "@canva/app-components";
|
|
2
2
|
import { Box } from "@canva/app-ui-kit";
|
|
3
|
+
import "@canva/app-ui-kit/styles.css";
|
|
3
4
|
import { findResources } from "./adapter";
|
|
4
|
-
import {
|
|
5
|
+
import { useConfig } from "./config";
|
|
5
6
|
import * as styles from "./index.css";
|
|
6
|
-
import "@canva/app-ui-kit/styles.css";
|
|
7
7
|
|
|
8
8
|
export function App() {
|
|
9
|
+
const config = useConfig();
|
|
9
10
|
return (
|
|
10
11
|
<Box className={styles.rootWrapper}>
|
|
11
|
-
<SearchableListView
|
|
12
|
+
<SearchableListView
|
|
13
|
+
config={config}
|
|
14
|
+
findResources={findResources}
|
|
15
|
+
// TODO remove `saveExportedDesign` and `config.export` if your app does not support exporting the Canva design into an external platform
|
|
16
|
+
saveExportedDesign={(
|
|
17
|
+
exportedDesignUrl: string,
|
|
18
|
+
containerId: string | undefined,
|
|
19
|
+
designTitle: string | undefined,
|
|
20
|
+
) => {
|
|
21
|
+
// TODO update the function to save the design to your platform
|
|
22
|
+
return new Promise((resolve) => {
|
|
23
|
+
setTimeout(() => {
|
|
24
|
+
// eslint-disable-next-line no-console
|
|
25
|
+
console.info(
|
|
26
|
+
`Saving file "${designTitle}" from ${exportedDesignUrl} to ${config.serviceName} container id: ${containerId}`,
|
|
27
|
+
);
|
|
28
|
+
resolve({ success: true });
|
|
29
|
+
}, 1000);
|
|
30
|
+
});
|
|
31
|
+
}}
|
|
32
|
+
/>
|
|
12
33
|
</Box>
|
|
13
34
|
);
|
|
14
35
|
}
|
|
@@ -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,30 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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";
|
|
7
9
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
* @returns {Object}
|
|
22
|
-
*/
|
|
23
|
-
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({
|
|
24
23
|
devConfig,
|
|
25
24
|
appEntry = path.join(process.cwd(), "src", "index.tsx"),
|
|
26
25
|
backendHost = process.env.CANVA_BACKEND_HOST,
|
|
27
|
-
|
|
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 {
|
|
28
34
|
const mode = devConfig ? "development" : "production";
|
|
29
35
|
|
|
30
36
|
if (!backendHost) {
|
|
@@ -45,9 +51,14 @@ function buildConfig({
|
|
|
45
51
|
return {
|
|
46
52
|
mode,
|
|
47
53
|
context: path.resolve(process.cwd(), "./"),
|
|
48
|
-
entry:
|
|
49
|
-
|
|
50
|
-
|
|
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
|
+
},
|
|
51
62
|
target: "web",
|
|
52
63
|
resolve: {
|
|
53
64
|
alias: {
|
|
@@ -59,7 +70,7 @@ function buildConfig({
|
|
|
59
70
|
extensions: [".ts", ".tsx", ".js", ".css", ".svg", ".woff", ".woff2"],
|
|
60
71
|
},
|
|
61
72
|
infrastructureLogging: {
|
|
62
|
-
level: "none",
|
|
73
|
+
level: inHarness ? "info" : "none",
|
|
63
74
|
},
|
|
64
75
|
module: {
|
|
65
76
|
rules: [
|
|
@@ -171,34 +182,26 @@ function buildConfig({
|
|
|
171
182
|
new DefinePlugin({
|
|
172
183
|
BACKEND_HOST: JSON.stringify(backendHost),
|
|
173
184
|
}),
|
|
174
|
-
// Apps can only submit a single JS file via the
|
|
185
|
+
// Apps can only submit a single JS file via the Developer Portal
|
|
175
186
|
new optimize.LimitChunkCountPlugin({ maxChunks: 1 }),
|
|
176
|
-
],
|
|
187
|
+
].filter(Boolean),
|
|
177
188
|
...buildDevConfig(devConfig),
|
|
178
189
|
};
|
|
179
190
|
}
|
|
180
191
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
* @param {boolean} [options.enableHmr]
|
|
186
|
-
* @param {boolean} [options.enableHttps]
|
|
187
|
-
* @param {string} [options.appOrigin]
|
|
188
|
-
* @param {string} [options.appId] - Deprecated in favour of appOrigin
|
|
189
|
-
* @param {string} [options.certFile]
|
|
190
|
-
* @param {string} [options.keyFile]
|
|
191
|
-
* @returns {Object|null}
|
|
192
|
-
*/
|
|
193
|
-
function buildDevConfig(options) {
|
|
192
|
+
function buildDevConfig(options?: DevConfig): {
|
|
193
|
+
devtool?: string;
|
|
194
|
+
devServer?: DevServerConfiguration;
|
|
195
|
+
} {
|
|
194
196
|
if (!options) {
|
|
195
|
-
return
|
|
197
|
+
return {};
|
|
196
198
|
}
|
|
197
199
|
|
|
198
200
|
const { port, enableHmr, appOrigin, appId, enableHttps, certFile, keyFile } =
|
|
199
201
|
options;
|
|
202
|
+
const host = "localhost";
|
|
200
203
|
|
|
201
|
-
let devServer = {
|
|
204
|
+
let devServer: DevServerConfiguration = {
|
|
202
205
|
server: enableHttps
|
|
203
206
|
? {
|
|
204
207
|
type: "https",
|
|
@@ -208,7 +211,8 @@ function buildDevConfig(options) {
|
|
|
208
211
|
},
|
|
209
212
|
}
|
|
210
213
|
: "http",
|
|
211
|
-
host
|
|
214
|
+
host,
|
|
215
|
+
allowedHosts: [host],
|
|
212
216
|
historyApiFallback: {
|
|
213
217
|
rewrites: [{ from: /^\/$/, to: "/app.js" }],
|
|
214
218
|
},
|
|
@@ -225,31 +229,13 @@ function buildDevConfig(options) {
|
|
|
225
229
|
if (enableHmr && appOrigin) {
|
|
226
230
|
devServer = {
|
|
227
231
|
...devServer,
|
|
228
|
-
allowedHosts: new URL(appOrigin).hostname,
|
|
232
|
+
allowedHosts: [host, new URL(appOrigin).hostname],
|
|
229
233
|
headers: {
|
|
230
234
|
"Access-Control-Allow-Origin": appOrigin,
|
|
231
235
|
"Access-Control-Allow-Credentials": "true",
|
|
232
236
|
"Access-Control-Allow-Private-Network": "true",
|
|
233
237
|
},
|
|
234
238
|
};
|
|
235
|
-
} else if (enableHmr && appId) {
|
|
236
|
-
// Deprecated - App ID should not be used to configure HMR in the future and can be safely removed
|
|
237
|
-
// after a few months.
|
|
238
|
-
|
|
239
|
-
console.warn(
|
|
240
|
-
"Enabling Hot Module Replacement (HMR) with an App ID is deprecated, please see the README.md on how to update.",
|
|
241
|
-
);
|
|
242
|
-
|
|
243
|
-
const appDomain = `app-${appId.toLowerCase().trim()}.canva-apps.com`;
|
|
244
|
-
devServer = {
|
|
245
|
-
...devServer,
|
|
246
|
-
allowedHosts: appDomain,
|
|
247
|
-
headers: {
|
|
248
|
-
"Access-Control-Allow-Origin": `https://${appDomain}`,
|
|
249
|
-
"Access-Control-Allow-Credentials": "true",
|
|
250
|
-
"Access-Control-Allow-Private-Network": "true",
|
|
251
|
-
},
|
|
252
|
-
};
|
|
253
239
|
} else {
|
|
254
240
|
if (enableHmr && !appOrigin) {
|
|
255
241
|
console.warn(
|
|
@@ -265,6 +251,4 @@ function buildDevConfig(options) {
|
|
|
265
251
|
};
|
|
266
252
|
}
|
|
267
253
|
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
module.exports.buildConfig = buildConfig;
|
|
254
|
+
export default buildConfig;
|