@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.
- package/CHANGELOG.md +26 -0
- package/README.md +1 -9
- package/cli.js +625 -626
- package/package.json +2 -3
- package/templates/base/backend/base_backend/create.ts +0 -114
- package/templates/base/backend/database/database.ts +0 -42
- package/templates/base/backend/routers/auth.ts +0 -288
- package/templates/base/declarations/declarations.d.ts +0 -29
- package/templates/base/eslint.config.mjs +0 -14
- package/templates/base/package.json +0 -91
- package/templates/base/scripts/copy_env.ts +0 -13
- package/templates/base/scripts/ssl/ssl.ts +0 -131
- package/templates/base/scripts/start/app_runner.ts +0 -223
- package/templates/base/scripts/start/context.ts +0 -171
- package/templates/base/scripts/start/start.ts +0 -46
- package/templates/base/scripts/start.tests.ts +0 -61
- package/templates/base/styles/components.css +0 -38
- package/templates/base/tsconfig.json +0 -56
- package/templates/base/webpack.config.ts +0 -247
- package/templates/common/.env.template +0 -6
- package/templates/common/.gitignore.template +0 -8
- package/templates/common/.nvmrc +0 -1
- package/templates/common/.prettierrc +0 -21
- package/templates/common/LICENSE.md +0 -48
- package/templates/common/README.md +0 -179
- package/templates/common/jest.config.mjs +0 -35
- package/templates/common/jest.setup.ts +0 -35
- package/templates/content_publisher/README.md +0 -58
- package/templates/content_publisher/canva-app.json +0 -17
- package/templates/content_publisher/declarations/declarations.d.ts +0 -29
- package/templates/content_publisher/eslint.config.mjs +0 -14
- package/templates/content_publisher/package.json +0 -90
- package/templates/content_publisher/scripts/copy_env.ts +0 -13
- package/templates/content_publisher/scripts/ssl/ssl.ts +0 -131
- package/templates/content_publisher/scripts/start/app_runner.ts +0 -223
- package/templates/content_publisher/scripts/start/context.ts +0 -171
- package/templates/content_publisher/scripts/start/start.ts +0 -46
- package/templates/content_publisher/src/index.tsx +0 -4
- package/templates/content_publisher/src/intents/content_publisher/index.tsx +0 -107
- package/templates/content_publisher/src/intents/content_publisher/post_preview.tsx +0 -240
- package/templates/content_publisher/src/intents/content_publisher/preview_ui.tsx +0 -62
- package/templates/content_publisher/src/intents/content_publisher/settings_ui.tsx +0 -81
- package/templates/content_publisher/src/intents/content_publisher/types.ts +0 -29
- package/templates/content_publisher/styles/components.css +0 -38
- package/templates/content_publisher/styles/preview_ui.css +0 -49
- package/templates/content_publisher/tsconfig.json +0 -56
- package/templates/content_publisher/webpack.config.ts +0 -247
- package/templates/dam/backend/routers/dam.ts +0 -108
- package/templates/dam/backend/server.ts +0 -65
- package/templates/dam/canva-app.json +0 -25
- package/templates/dam/declarations/declarations.d.ts +0 -29
- package/templates/dam/eslint.config.mjs +0 -14
- package/templates/dam/package.json +0 -97
- package/templates/dam/scripts/copy_env.ts +0 -13
- package/templates/dam/scripts/ssl/ssl.ts +0 -131
- package/templates/dam/scripts/start/app_runner.ts +0 -223
- package/templates/dam/scripts/start/context.ts +0 -171
- package/templates/dam/scripts/start/start.ts +0 -46
- package/templates/dam/src/index.tsx +0 -4
- package/templates/dam/src/intents/design_editor/adapter.ts +0 -44
- package/templates/dam/src/intents/design_editor/app.tsx +0 -35
- package/templates/dam/src/intents/design_editor/config.ts +0 -220
- package/templates/dam/src/intents/design_editor/index.css +0 -3
- package/templates/dam/src/intents/design_editor/index.tsx +0 -25
- package/templates/dam/tsconfig.json +0 -56
- package/templates/dam/utils/backend/base_backend/create.ts +0 -114
- package/templates/dam/webpack.config.ts +0 -247
- package/templates/data_connector/README.md +0 -84
- package/templates/data_connector/canva-app.json +0 -21
- package/templates/data_connector/declarations/declarations.d.ts +0 -29
- package/templates/data_connector/eslint.config.mjs +0 -14
- package/templates/data_connector/package.json +0 -92
- package/templates/data_connector/scripts/copy_env.ts +0 -13
- package/templates/data_connector/scripts/ssl/ssl.ts +0 -131
- package/templates/data_connector/scripts/start/app_runner.ts +0 -223
- package/templates/data_connector/scripts/start/context.ts +0 -171
- package/templates/data_connector/scripts/start/start.ts +0 -46
- package/templates/data_connector/src/api/connect_client.ts +0 -6
- package/templates/data_connector/src/api/data_source.ts +0 -97
- package/templates/data_connector/src/api/data_sources/designs.tsx +0 -296
- package/templates/data_connector/src/api/data_sources/index.ts +0 -4
- package/templates/data_connector/src/api/data_sources/templates.tsx +0 -328
- package/templates/data_connector/src/api/fetch_data_table.ts +0 -55
- package/templates/data_connector/src/api/index.ts +0 -4
- package/templates/data_connector/src/api/oauth.ts +0 -8
- package/templates/data_connector/src/api/tests/data_source.test.tsx +0 -99
- package/templates/data_connector/src/components/app_error.tsx +0 -15
- package/templates/data_connector/src/components/footer.tsx +0 -26
- package/templates/data_connector/src/components/header.tsx +0 -40
- package/templates/data_connector/src/components/index.ts +0 -3
- package/templates/data_connector/src/components/inputs/messages.tsx +0 -95
- package/templates/data_connector/src/components/inputs/search_filter.tsx +0 -109
- package/templates/data_connector/src/components/inputs/select_field.tsx +0 -26
- package/templates/data_connector/src/context/app_context.tsx +0 -125
- package/templates/data_connector/src/context/index.ts +0 -2
- package/templates/data_connector/src/context/use_app_context.ts +0 -17
- package/templates/data_connector/src/index.tsx +0 -4
- package/templates/data_connector/src/intents/data_connector/app.tsx +0 -20
- package/templates/data_connector/src/intents/data_connector/entrypoint.tsx +0 -70
- package/templates/data_connector/src/intents/data_connector/home.tsx +0 -21
- package/templates/data_connector/src/intents/data_connector/index.tsx +0 -56
- package/templates/data_connector/src/pages/data_source_config.tsx +0 -9
- package/templates/data_connector/src/pages/error.tsx +0 -37
- package/templates/data_connector/src/pages/index.ts +0 -4
- package/templates/data_connector/src/pages/login.tsx +0 -145
- package/templates/data_connector/src/pages/select_source.tsx +0 -24
- package/templates/data_connector/src/routes/index.ts +0 -2
- package/templates/data_connector/src/routes/paths.ts +0 -7
- package/templates/data_connector/src/routes/protected_route.tsx +0 -26
- package/templates/data_connector/src/routes/routes.tsx +0 -42
- package/templates/data_connector/src/utils/data_params.ts +0 -17
- package/templates/data_connector/src/utils/data_table.ts +0 -116
- package/templates/data_connector/src/utils/fetch_result.ts +0 -36
- package/templates/data_connector/src/utils/index.ts +0 -2
- package/templates/data_connector/src/utils/tests/data_table.test.ts +0 -133
- package/templates/data_connector/styles/components.css +0 -38
- package/templates/data_connector/tsconfig.json +0 -56
- package/templates/data_connector/webpack.config.ts +0 -247
- package/templates/gen_ai/README.md +0 -27
- package/templates/gen_ai/backend/routers/image.ts +0 -232
- package/templates/gen_ai/backend/server.ts +0 -65
- package/templates/gen_ai/canva-app.json +0 -25
- package/templates/gen_ai/declarations/declarations.d.ts +0 -29
- package/templates/gen_ai/eslint.config.mjs +0 -14
- package/templates/gen_ai/package.json +0 -101
- package/templates/gen_ai/scripts/copy_env.ts +0 -13
- package/templates/gen_ai/scripts/ssl/ssl.ts +0 -131
- package/templates/gen_ai/scripts/start/app_runner.ts +0 -223
- package/templates/gen_ai/scripts/start/context.ts +0 -171
- package/templates/gen_ai/scripts/start/start.ts +0 -46
- package/templates/gen_ai/src/api/api.ts +0 -194
- package/templates/gen_ai/src/api/index.ts +0 -1
- package/templates/gen_ai/src/components/app_error.tsx +0 -18
- package/templates/gen_ai/src/components/footer.messages.ts +0 -48
- package/templates/gen_ai/src/components/footer.tsx +0 -156
- package/templates/gen_ai/src/components/image_grid.tsx +0 -103
- package/templates/gen_ai/src/components/index.ts +0 -7
- package/templates/gen_ai/src/components/loading_results.tsx +0 -169
- package/templates/gen_ai/src/components/prompt_input.messages.ts +0 -14
- package/templates/gen_ai/src/components/prompt_input.tsx +0 -154
- package/templates/gen_ai/src/components/remaining_credits.tsx +0 -84
- package/templates/gen_ai/src/components/report_box.tsx +0 -54
- package/templates/gen_ai/src/components/tests/remaining_credit.tests.tsx +0 -47
- package/templates/gen_ai/src/config.ts +0 -21
- package/templates/gen_ai/src/context/app_context.tsx +0 -153
- package/templates/gen_ai/src/context/context.messages.ts +0 -30
- package/templates/gen_ai/src/context/index.ts +0 -2
- package/templates/gen_ai/src/context/use_app_context.ts +0 -17
- package/templates/gen_ai/src/index.tsx +0 -4
- package/templates/gen_ai/src/intents/design_editor/app.tsx +0 -19
- package/templates/gen_ai/src/intents/design_editor/home.tsx +0 -13
- package/templates/gen_ai/src/intents/design_editor/index.tsx +0 -17
- package/templates/gen_ai/src/pages/error.tsx +0 -41
- package/templates/gen_ai/src/pages/generate.tsx +0 -9
- package/templates/gen_ai/src/pages/index.ts +0 -3
- package/templates/gen_ai/src/pages/results.tsx +0 -31
- package/templates/gen_ai/src/routes/index.ts +0 -1
- package/templates/gen_ai/src/routes/paths.ts +0 -4
- package/templates/gen_ai/src/routes/routes.tsx +0 -24
- package/templates/gen_ai/src/utils/index.ts +0 -1
- package/templates/gen_ai/src/utils/obscenity_filter.ts +0 -33
- package/templates/gen_ai/styles/components.css +0 -38
- package/templates/gen_ai/styles/utils.css +0 -3
- package/templates/gen_ai/tsconfig.json +0 -56
- package/templates/gen_ai/utils/backend/base_backend/create.ts +0 -114
- package/templates/gen_ai/webpack.config.ts +0 -247
- package/templates/hello_world/canva-app.json +0 -21
- package/templates/hello_world/declarations/declarations.d.ts +0 -29
- package/templates/hello_world/eslint.config.mjs +0 -14
- package/templates/hello_world/package.json +0 -90
- package/templates/hello_world/scripts/copy_env.ts +0 -13
- package/templates/hello_world/scripts/ssl/ssl.ts +0 -131
- package/templates/hello_world/scripts/start/app_runner.ts +0 -223
- package/templates/hello_world/scripts/start/context.ts +0 -171
- package/templates/hello_world/scripts/start/start.ts +0 -46
- package/templates/hello_world/src/index.tsx +0 -4
- package/templates/hello_world/src/intents/design_editor/app.tsx +0 -86
- package/templates/hello_world/src/intents/design_editor/index.tsx +0 -25
- package/templates/hello_world/src/intents/design_editor/tests/__snapshots__/app.tests.tsx.snap +0 -45
- package/templates/hello_world/src/intents/design_editor/tests/app.tests.tsx +0 -92
- package/templates/hello_world/styles/components.css +0 -38
- package/templates/hello_world/tsconfig.json +0 -56
- package/templates/hello_world/webpack.config.ts +0 -247
- package/templates/mls/README.md +0 -81
- package/templates/mls/canva-app.json +0 -25
- package/templates/mls/declarations/declarations.d.ts +0 -29
- package/templates/mls/eslint.config.mjs +0 -14
- package/templates/mls/jest.config.mjs +0 -36
- package/templates/mls/jest.setup.ts +0 -39
- package/templates/mls/package.json +0 -117
- package/templates/mls/scripts/copy_env.ts +0 -13
- package/templates/mls/scripts/ssl/ssl.ts +0 -131
- package/templates/mls/scripts/start/app_runner.ts +0 -223
- package/templates/mls/scripts/start/context.ts +0 -171
- package/templates/mls/scripts/start/start.ts +0 -46
- package/templates/mls/src/__tests__/app.tests.tsx +0 -11
- package/templates/mls/src/__tests__/office_selection_page.tests.tsx +0 -72
- package/templates/mls/src/__tests__/utils.tsx +0 -19
- package/templates/mls/src/adapter.ts +0 -126
- package/templates/mls/src/components/agent/agent_card.tsx +0 -57
- package/templates/mls/src/components/agent/agent_grid.tsx +0 -37
- package/templates/mls/src/components/agent/agent_list.tsx +0 -17
- package/templates/mls/src/components/agent/agent_search_filters.tsx +0 -88
- package/templates/mls/src/components/breadcrumb/breadcrumb.tsx +0 -40
- package/templates/mls/src/components/listing/listing_card.tsx +0 -64
- package/templates/mls/src/components/listing/listing_grid.tsx +0 -37
- package/templates/mls/src/components/listing/listing_list.tsx +0 -21
- package/templates/mls/src/components/listing/listing_search_filters.tsx +0 -145
- package/templates/mls/src/components/placeholders/placeholders.tsx +0 -65
- package/templates/mls/src/data.ts +0 -359
- package/templates/mls/src/index.tsx +0 -4
- package/templates/mls/src/intents/design_editor/app.tsx +0 -44
- package/templates/mls/src/intents/design_editor/index.tsx +0 -25
- package/templates/mls/src/pages/agent_details_page/agent_details_page.tsx +0 -175
- package/templates/mls/src/pages/list_page/agent_tab_panel.tsx +0 -126
- package/templates/mls/src/pages/list_page/list_page.tsx +0 -67
- package/templates/mls/src/pages/list_page/listing_tab_panel.tsx +0 -135
- package/templates/mls/src/pages/listing_details_page/listing_details_page.tsx +0 -418
- package/templates/mls/src/pages/loading_page/loading_page.tsx +0 -152
- package/templates/mls/src/pages/office_selection_page/office_selection_page.tsx +0 -144
- package/templates/mls/src/real_estate.type.ts +0 -44
- package/templates/mls/src/util/use_add_element.tsx +0 -62
- package/templates/mls/src/util/use_drag_element.tsx +0 -68
- package/templates/mls/styles/components.css +0 -38
- package/templates/mls/tsconfig.json +0 -54
- package/templates/mls/webpack.config.ts +0 -248
- package/templates/optional/.cursor/mcp.json +0 -8
- package/templates/optional/.vscode/extensions.json +0 -6
- package/templates/optional/.vscode/mcp.json +0 -9
- package/templates/optional/AGENTS.md +0 -154
- package/templates/optional/CLAUDE.md +0 -154
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
import type { JSX } from "react";
|
|
2
|
-
import { createContext, useEffect, useState } from "react";
|
|
3
|
-
import { useIntl } from "react-intl";
|
|
4
|
-
import type { ImageType } from "src/api";
|
|
5
|
-
import { getRemainingCredits } from "src/api";
|
|
6
|
-
import { ContextMessages as Messages } from "./context.messages";
|
|
7
|
-
|
|
8
|
-
export interface AppContextType {
|
|
9
|
-
appError: string;
|
|
10
|
-
setAppError: (value: string) => void;
|
|
11
|
-
creditsError: string;
|
|
12
|
-
setCreditsError: (value: string) => void;
|
|
13
|
-
loadingApp: boolean;
|
|
14
|
-
setLoadingApp: (value: boolean) => void;
|
|
15
|
-
isLoadingImages: boolean;
|
|
16
|
-
setIsLoadingImages: (value: boolean) => void;
|
|
17
|
-
jobId: string;
|
|
18
|
-
setJobId: (value: string) => void;
|
|
19
|
-
remainingCredits: number;
|
|
20
|
-
setRemainingCredits: (value: number) => void;
|
|
21
|
-
promptInput: string;
|
|
22
|
-
setPromptInput: (value: string) => void;
|
|
23
|
-
promptInputError: string;
|
|
24
|
-
setPromptInputError: (value: string) => void;
|
|
25
|
-
generatedImages: ImageType[];
|
|
26
|
-
setGeneratedImages: (value: ImageType[]) => void;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export const AppContext = createContext<AppContextType>({
|
|
30
|
-
appError: "",
|
|
31
|
-
setAppError: () => {},
|
|
32
|
-
creditsError: "",
|
|
33
|
-
setCreditsError: () => {},
|
|
34
|
-
loadingApp: true,
|
|
35
|
-
setLoadingApp: () => {},
|
|
36
|
-
isLoadingImages: false,
|
|
37
|
-
setIsLoadingImages: () => {},
|
|
38
|
-
jobId: "",
|
|
39
|
-
setJobId: () => {},
|
|
40
|
-
remainingCredits: 0,
|
|
41
|
-
setRemainingCredits: () => {},
|
|
42
|
-
promptInput: "",
|
|
43
|
-
setPromptInput: () => {},
|
|
44
|
-
promptInputError: "",
|
|
45
|
-
setPromptInputError: () => {},
|
|
46
|
-
generatedImages: [] as ImageType[],
|
|
47
|
-
setGeneratedImages: () => {},
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Provides application-wide state and methods using React Context.
|
|
52
|
-
* @param {object} props - The props object.
|
|
53
|
-
* @param {React.ReactNode} props.children - The children components wrapped by the provider.
|
|
54
|
-
* @returns {JSX.Element} The provider component.
|
|
55
|
-
* @description This provider component wraps the entire application to provide application-wide state and methods using React Context.
|
|
56
|
-
* It manages state related to app errors, loading status, remaining credits, user input for prompts, image styles, and generated images.
|
|
57
|
-
* It exposes these state values and setter methods to its child components via the AppContext.
|
|
58
|
-
* For more information on React Context, refer to the official React documentation: {@link https://react.dev/learn/passing-data-deeply-with-context}.
|
|
59
|
-
*/
|
|
60
|
-
export const ContextProvider = ({
|
|
61
|
-
children,
|
|
62
|
-
}: {
|
|
63
|
-
children: React.ReactNode;
|
|
64
|
-
}): JSX.Element => {
|
|
65
|
-
const [appError, setAppError] = useState<string>("");
|
|
66
|
-
const [loadingApp, setLoadingApp] = useState<boolean>(true); // set to true to prevent ui flash on load
|
|
67
|
-
const [isLoadingImages, setIsLoadingImages] = useState<boolean>(false);
|
|
68
|
-
const [jobId, setJobId] = useState<string>("");
|
|
69
|
-
const [remainingCredits, setRemainingCredits] = useState<number>(0);
|
|
70
|
-
const [promptInput, setPromptInput] = useState<string>("");
|
|
71
|
-
const [promptInputError, setPromptInputError] = useState<string>("");
|
|
72
|
-
const [generatedImages, setGeneratedImages] = useState<ImageType[]>([]);
|
|
73
|
-
const [creditsError, setCreditsError] = useState<string>("");
|
|
74
|
-
const intl = useIntl();
|
|
75
|
-
|
|
76
|
-
// Fetches initial data on component mount
|
|
77
|
-
useEffect(() => {
|
|
78
|
-
const fetchDataOnMount = async () => {
|
|
79
|
-
try {
|
|
80
|
-
setLoadingApp(true);
|
|
81
|
-
|
|
82
|
-
// Fetch remaining credits
|
|
83
|
-
try {
|
|
84
|
-
const { credits } = await getRemainingCredits();
|
|
85
|
-
setRemainingCredits(credits);
|
|
86
|
-
} catch (error) {
|
|
87
|
-
setAppError(
|
|
88
|
-
intl.formatMessage(Messages.appErrorGetRemainingCreditsFailed),
|
|
89
|
-
);
|
|
90
|
-
// eslint-disable-next-line no-console
|
|
91
|
-
console.error("Error fetching remaining credits:", error);
|
|
92
|
-
}
|
|
93
|
-
} catch (error) {
|
|
94
|
-
setAppError(intl.formatMessage(Messages.appErrorGeneral));
|
|
95
|
-
// eslint-disable-next-line no-console
|
|
96
|
-
console.error("Error fetching data:", error);
|
|
97
|
-
} finally {
|
|
98
|
-
setLoadingApp(false);
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
fetchDataOnMount();
|
|
103
|
-
}, []);
|
|
104
|
-
|
|
105
|
-
// Manages errors related to remaining credits
|
|
106
|
-
useEffect(() => {
|
|
107
|
-
if (loadingApp || remainingCredits > 0) {
|
|
108
|
-
setCreditsError("");
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const errorMessage = intl.formatMessage(Messages.alertNotEnoughCredits);
|
|
113
|
-
|
|
114
|
-
setCreditsError(errorMessage);
|
|
115
|
-
}, [loadingApp, remainingCredits]);
|
|
116
|
-
|
|
117
|
-
const setPromptInputHandler = (value: string) => {
|
|
118
|
-
if (
|
|
119
|
-
promptInputError ===
|
|
120
|
-
intl.formatMessage(Messages.promptMissingErrorMessage)
|
|
121
|
-
) {
|
|
122
|
-
setPromptInputError("");
|
|
123
|
-
}
|
|
124
|
-
if (value === "") {
|
|
125
|
-
setPromptInputError("");
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
setPromptInput(value);
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
const value: AppContextType = {
|
|
132
|
-
appError,
|
|
133
|
-
setAppError,
|
|
134
|
-
creditsError,
|
|
135
|
-
setCreditsError,
|
|
136
|
-
loadingApp,
|
|
137
|
-
setLoadingApp,
|
|
138
|
-
isLoadingImages,
|
|
139
|
-
setIsLoadingImages,
|
|
140
|
-
jobId,
|
|
141
|
-
setJobId,
|
|
142
|
-
remainingCredits,
|
|
143
|
-
setRemainingCredits,
|
|
144
|
-
promptInput,
|
|
145
|
-
setPromptInput: setPromptInputHandler,
|
|
146
|
-
promptInputError,
|
|
147
|
-
setPromptInputError,
|
|
148
|
-
generatedImages,
|
|
149
|
-
setGeneratedImages,
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
return <AppContext.Provider value={value}>{children}</AppContext.Provider>;
|
|
153
|
-
};
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { defineMessages } from "react-intl";
|
|
2
|
-
|
|
3
|
-
export const ContextMessages = defineMessages({
|
|
4
|
-
/** Messages related to handling errors that occur during operations. */
|
|
5
|
-
appErrorGeneral: {
|
|
6
|
-
defaultMessage: "An unexpected error occurred. Please try again later.",
|
|
7
|
-
description:
|
|
8
|
-
"A message to indicate that an unexpected error occurred, but no more information is available",
|
|
9
|
-
},
|
|
10
|
-
appErrorGetRemainingCreditsFailed: {
|
|
11
|
-
defaultMessage: "Retrieving remaining credits has failed.",
|
|
12
|
-
description:
|
|
13
|
-
"A message to indicate that there was a failure to get the number of credits the user has",
|
|
14
|
-
},
|
|
15
|
-
|
|
16
|
-
/** Messages related to prompts and user input validation. */
|
|
17
|
-
promptMissingErrorMessage: {
|
|
18
|
-
defaultMessage: "Please describe what you want to create",
|
|
19
|
-
description:
|
|
20
|
-
"An error message to indicate that the prompt was empty and should be supplied",
|
|
21
|
-
},
|
|
22
|
-
|
|
23
|
-
/** Messages related to credits, including their availability and purchasing options. */
|
|
24
|
-
alertNotEnoughCredits: {
|
|
25
|
-
defaultMessage:
|
|
26
|
-
"You don’t have enough credits left to generate an image. Please purchase more.",
|
|
27
|
-
description:
|
|
28
|
-
"A message to indicate that the user doesn't have enough credits to generate an image, and will need to buy more to continue",
|
|
29
|
-
},
|
|
30
|
-
});
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { useContext } from "react";
|
|
2
|
-
import type { AppContextType } from "./app_context";
|
|
3
|
-
import { AppContext } from "./app_context";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* A custom React hook to access the application-wide state and methods provided by the ContextProvider using React Context.
|
|
7
|
-
* @returns {AppContextType} - An object containing application-wide state and methods.
|
|
8
|
-
* @throws {Error} - Throws an error if used outside the context of a ContextProvider.
|
|
9
|
-
* @description This hook allows components to access the application-wide state and methods provided by the ContextProvider using React Context. It retrieves the context value using the useContext hook and ensures that the context is available. If used outside the context of an ContextProvider, it throws an error instructing developers to use it within an ContextProvider.
|
|
10
|
-
*/
|
|
11
|
-
export const useAppContext = (): AppContextType => {
|
|
12
|
-
const context = useContext(AppContext);
|
|
13
|
-
if (!context) {
|
|
14
|
-
throw new Error("useAppContext must be used within a ContextProvider");
|
|
15
|
-
}
|
|
16
|
-
return context;
|
|
17
|
-
};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { AppI18nProvider } from "@canva/app-i18n-kit";
|
|
2
|
-
import { AppUiProvider } from "@canva/app-ui-kit";
|
|
3
|
-
import { ErrorBoundary } from "react-error-boundary";
|
|
4
|
-
import { createHashRouter, RouterProvider } from "react-router-dom";
|
|
5
|
-
import { ContextProvider } from "../../context";
|
|
6
|
-
import { ErrorPage } from "../../pages";
|
|
7
|
-
import { routes } from "../../routes";
|
|
8
|
-
|
|
9
|
-
export const App = () => (
|
|
10
|
-
<AppI18nProvider>
|
|
11
|
-
<AppUiProvider>
|
|
12
|
-
<ErrorBoundary fallback={<ErrorPage />}>
|
|
13
|
-
<ContextProvider>
|
|
14
|
-
<RouterProvider router={createHashRouter(routes)} />
|
|
15
|
-
</ContextProvider>
|
|
16
|
-
</ErrorBoundary>
|
|
17
|
-
</AppUiProvider>
|
|
18
|
-
</AppI18nProvider>
|
|
19
|
-
);
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Rows } from "@canva/app-ui-kit";
|
|
2
|
-
import { Outlet } from "react-router-dom";
|
|
3
|
-
import * as styles from "styles/components.css";
|
|
4
|
-
import { Footer } from "../../components";
|
|
5
|
-
|
|
6
|
-
export const Home = () => (
|
|
7
|
-
<div className={styles.scrollContainer}>
|
|
8
|
-
<Rows spacing="3u">
|
|
9
|
-
<Outlet />
|
|
10
|
-
<Footer />
|
|
11
|
-
</Rows>
|
|
12
|
-
</div>
|
|
13
|
-
);
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import "@canva/app-ui-kit/styles.css";
|
|
2
|
-
import type { DesignEditorIntent } from "@canva/intents/design";
|
|
3
|
-
import { createRoot } from "react-dom/client";
|
|
4
|
-
import { App } from "./app";
|
|
5
|
-
|
|
6
|
-
async function render() {
|
|
7
|
-
const root = createRoot(document.getElementById("root") as Element);
|
|
8
|
-
|
|
9
|
-
root.render(<App />);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const designEditor: DesignEditorIntent = { render };
|
|
13
|
-
export default designEditor;
|
|
14
|
-
|
|
15
|
-
if (module.hot) {
|
|
16
|
-
module.hot.accept("./app", render);
|
|
17
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { Button, Rows, Text } from "@canva/app-ui-kit";
|
|
2
|
-
import { FormattedMessage, useIntl } from "react-intl";
|
|
3
|
-
import { useNavigate } from "react-router-dom";
|
|
4
|
-
import { useAppContext } from "src/context";
|
|
5
|
-
import { Paths } from "src/routes/paths";
|
|
6
|
-
import * as styles from "styles/components.css";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Bare bones Error Page, please add relevant information and behavior that your app requires.
|
|
10
|
-
*/
|
|
11
|
-
export const ErrorPage = () => {
|
|
12
|
-
const navigate = useNavigate();
|
|
13
|
-
const { setPromptInput, setIsLoadingImages } = useAppContext();
|
|
14
|
-
const intl = useIntl();
|
|
15
|
-
|
|
16
|
-
const onClick = () => {
|
|
17
|
-
setPromptInput("");
|
|
18
|
-
setIsLoadingImages(false);
|
|
19
|
-
navigate(Paths.HOME);
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
return (
|
|
23
|
-
<div className={styles.scrollContainer}>
|
|
24
|
-
<Rows spacing="2u">
|
|
25
|
-
<Text>
|
|
26
|
-
<FormattedMessage
|
|
27
|
-
defaultMessage="Something went wrong."
|
|
28
|
-
description="A message to indicate that something went wrong, but no more information is available"
|
|
29
|
-
/>
|
|
30
|
-
</Text>
|
|
31
|
-
<Button variant="primary" onClick={onClick} stretch={true}>
|
|
32
|
-
{intl.formatMessage({
|
|
33
|
-
defaultMessage: "Start over",
|
|
34
|
-
description:
|
|
35
|
-
"A button label to clear the error and the prompt and start again",
|
|
36
|
-
})}
|
|
37
|
-
</Button>
|
|
38
|
-
</Rows>
|
|
39
|
-
</div>
|
|
40
|
-
);
|
|
41
|
-
};
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { Rows } from "@canva/app-ui-kit";
|
|
2
|
-
import {
|
|
3
|
-
AppError,
|
|
4
|
-
ImageGrid,
|
|
5
|
-
LoadingResults,
|
|
6
|
-
PromptInput,
|
|
7
|
-
ReportBox,
|
|
8
|
-
} from "src/components";
|
|
9
|
-
import { EXPECTED_LOADING_TIME_IN_SECONDS } from "src/config";
|
|
10
|
-
import { useAppContext } from "src/context";
|
|
11
|
-
|
|
12
|
-
export const ResultsPage = () => {
|
|
13
|
-
const { isLoadingImages } = useAppContext();
|
|
14
|
-
|
|
15
|
-
if (isLoadingImages) {
|
|
16
|
-
return (
|
|
17
|
-
<LoadingResults durationInSeconds={EXPECTED_LOADING_TIME_IN_SECONDS} />
|
|
18
|
-
);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
return (
|
|
22
|
-
<Rows spacing="1u">
|
|
23
|
-
<AppError />
|
|
24
|
-
<Rows spacing="2u">
|
|
25
|
-
<ImageGrid />
|
|
26
|
-
<PromptInput />
|
|
27
|
-
<ReportBox />
|
|
28
|
-
</Rows>
|
|
29
|
-
</Rows>
|
|
30
|
-
);
|
|
31
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./routes";
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { Home } from "src/intents/design_editor/home";
|
|
2
|
-
import { ErrorPage } from "src/pages/error";
|
|
3
|
-
import { GeneratePage } from "src/pages/generate";
|
|
4
|
-
import { ResultsPage } from "src/pages/results";
|
|
5
|
-
import { Paths } from "src/routes/paths";
|
|
6
|
-
|
|
7
|
-
export const routes = [
|
|
8
|
-
{
|
|
9
|
-
path: Paths.HOME,
|
|
10
|
-
element: <Home />,
|
|
11
|
-
errorElement: <ErrorPage />,
|
|
12
|
-
children: [
|
|
13
|
-
{
|
|
14
|
-
index: true,
|
|
15
|
-
element: <GeneratePage />,
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
path: Paths.RESULTS,
|
|
19
|
-
element: <ResultsPage />,
|
|
20
|
-
},
|
|
21
|
-
// @TODO: Add additional pages and routes as needed.
|
|
22
|
-
],
|
|
23
|
-
},
|
|
24
|
-
];
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./obscenity_filter";
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
englishDataset,
|
|
3
|
-
englishRecommendedTransformers,
|
|
4
|
-
RegExpMatcher,
|
|
5
|
-
} from "obscenity";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Retrieves a list of obscene words from the given input string.
|
|
9
|
-
* @param {string} input The input string to search for obscene words.
|
|
10
|
-
* @returns {string[]} An array of unique obscene words found in the input string.
|
|
11
|
-
*/
|
|
12
|
-
export const getObsceneWords = (input: string): string[] => {
|
|
13
|
-
const matcher = new RegExpMatcher({
|
|
14
|
-
...englishDataset.build(),
|
|
15
|
-
...englishRecommendedTransformers,
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
// Find all matches in the input string, sorted by their position.
|
|
19
|
-
const matches = matcher.getAllMatches(input, true);
|
|
20
|
-
|
|
21
|
-
const obsceneWords: string[] = [];
|
|
22
|
-
|
|
23
|
-
for (const match of matches) {
|
|
24
|
-
const { phraseMetadata } =
|
|
25
|
-
englishDataset.getPayloadWithPhraseMetadata(match);
|
|
26
|
-
if (phraseMetadata?.originalWord) {
|
|
27
|
-
obsceneWords.push(phraseMetadata.originalWord);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// Return an array of unique obscene words.
|
|
32
|
-
return [...new Set(obsceneWords)];
|
|
33
|
-
};
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/* Scroll container */
|
|
2
|
-
.scrollContainer {
|
|
3
|
-
box-sizing: border-box;
|
|
4
|
-
overflow-y: scroll;
|
|
5
|
-
height: 100%;
|
|
6
|
-
padding-top: var(--ui-kit-space-200);
|
|
7
|
-
padding-right: var(--ui-kit-space-200);
|
|
8
|
-
padding-bottom: var(--ui-kit-space-200);
|
|
9
|
-
|
|
10
|
-
/* for firefox */
|
|
11
|
-
scrollbar-width: thin;
|
|
12
|
-
scrollbar-color: var(--ui-kit-color-content-placeholder-fg) transparent;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
.scrollContainer::-webkit-scrollbar {
|
|
16
|
-
position: absolute;
|
|
17
|
-
width: var(--ui-kit-base-unit);
|
|
18
|
-
height: 0;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
.scrollContainer::-webkit-scrollbar-track {
|
|
22
|
-
background: transparent;
|
|
23
|
-
width: var(--ui-kit-base-unit);
|
|
24
|
-
margin-top: var(--ui-kit-space-100);
|
|
25
|
-
margin-bottom: var(--ui-kit-space-100);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
.scrollContainer::-webkit-scrollbar-thumb {
|
|
29
|
-
border-radius: var(--ui-kit-radius-element-standard);
|
|
30
|
-
background: var(--ui-kit-color-content-placeholder-fg);
|
|
31
|
-
visibility: hidden;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
.scrollContainer:hover::-webkit-scrollbar-thumb,
|
|
35
|
-
.scrollContainer:focus::-webkit-scrollbar-thumb,
|
|
36
|
-
.scrollContainer:focus-within::-webkit-scrollbar-thumb {
|
|
37
|
-
visibility: visible;
|
|
38
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"jsx": "react-jsx",
|
|
4
|
-
"lib": [
|
|
5
|
-
"dom",
|
|
6
|
-
"dom.iterable",
|
|
7
|
-
"es2018",
|
|
8
|
-
"es2019.array",
|
|
9
|
-
"es2019.object",
|
|
10
|
-
"es2019.string",
|
|
11
|
-
"es2020.promise",
|
|
12
|
-
"es2020.string"
|
|
13
|
-
],
|
|
14
|
-
"types": ["node", "webpack-env", "jest"],
|
|
15
|
-
"composite": false,
|
|
16
|
-
"declaration": false,
|
|
17
|
-
"declarationMap": false,
|
|
18
|
-
"experimentalDecorators": true,
|
|
19
|
-
"importHelpers": true,
|
|
20
|
-
"noImplicitOverride": true,
|
|
21
|
-
"moduleResolution": "bundler",
|
|
22
|
-
"esModuleInterop": true,
|
|
23
|
-
"rootDir": ".",
|
|
24
|
-
"outDir": "dist",
|
|
25
|
-
"strict": true,
|
|
26
|
-
"skipLibCheck": true,
|
|
27
|
-
"target": "ES2019",
|
|
28
|
-
"sourceMap": true,
|
|
29
|
-
"inlineSources": true,
|
|
30
|
-
"module": "ESNext",
|
|
31
|
-
"noImplicitAny": true,
|
|
32
|
-
"noImplicitReturns": true,
|
|
33
|
-
"noFallthroughCasesInSwitch": true,
|
|
34
|
-
"noUncheckedIndexedAccess": true,
|
|
35
|
-
"removeComments": true,
|
|
36
|
-
"preserveConstEnums": true,
|
|
37
|
-
"allowSyntheticDefaultImports": true,
|
|
38
|
-
"baseUrl": "./",
|
|
39
|
-
"paths": {
|
|
40
|
-
"styles": ["./styles"]
|
|
41
|
-
}
|
|
42
|
-
},
|
|
43
|
-
"include": [
|
|
44
|
-
"./src/**/*",
|
|
45
|
-
"./backend/**/*",
|
|
46
|
-
"./utils/**/*",
|
|
47
|
-
"./scripts/**/*",
|
|
48
|
-
"./declarations/declarations.d.ts",
|
|
49
|
-
"./styles/**/*"
|
|
50
|
-
],
|
|
51
|
-
"ts-node": {
|
|
52
|
-
"compilerOptions": {
|
|
53
|
-
"module": "commonjs"
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-console */
|
|
2
|
-
import { TokenVerificationError } from "@canva/app-middleware";
|
|
3
|
-
import debug from "debug";
|
|
4
|
-
import express from "express";
|
|
5
|
-
import type { NextFunction, Request, Response } from "express";
|
|
6
|
-
import fs from "fs";
|
|
7
|
-
import http from "http";
|
|
8
|
-
import https from "https";
|
|
9
|
-
|
|
10
|
-
const serverDebug = debug("server");
|
|
11
|
-
|
|
12
|
-
interface BaseServer {
|
|
13
|
-
app: express.Express;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Starts the server on the address or port provided
|
|
17
|
-
* @param address port number or string address or if left undefined express defaults to port 3000
|
|
18
|
-
*/
|
|
19
|
-
start: (address: number | string | undefined) => void;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* createBaseServer instantiates a customised express server with:
|
|
24
|
-
* - json body handling
|
|
25
|
-
* - health check endpoint
|
|
26
|
-
* - catchall endpoint
|
|
27
|
-
* - error handler catch route
|
|
28
|
-
* - process termination handling
|
|
29
|
-
* - debug logging - prefix starting your server with `DEBUG=server npm run XXX`
|
|
30
|
-
*
|
|
31
|
-
* @returns BaseServer object containing the express app and a start function
|
|
32
|
-
*/
|
|
33
|
-
export function createBaseServer(router: express.Router): BaseServer {
|
|
34
|
-
const SHOULD_ENABLE_HTTPS = process.env?.SHOULD_ENABLE_HTTPS === "true";
|
|
35
|
-
const HTTPS_CERT_FILE = process.env?.HTTPS_CERT_FILE;
|
|
36
|
-
const HTTPS_KEY_FILE = process.env?.HTTPS_KEY_FILE;
|
|
37
|
-
|
|
38
|
-
const app = express();
|
|
39
|
-
app.use(express.json());
|
|
40
|
-
|
|
41
|
-
// It can help to provide an extra layer of obsecurity to reduce server fingerprinting.
|
|
42
|
-
app.disable("x-powered-by");
|
|
43
|
-
|
|
44
|
-
// Health check endpoint
|
|
45
|
-
app.get("/healthz", (req, res) => {
|
|
46
|
-
res.sendStatus(200);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
// logging middleware
|
|
50
|
-
app.use((req, _res, next) => {
|
|
51
|
-
serverDebug(`${new Date().toISOString()}: ${req.method} ${req.url}`);
|
|
52
|
-
next();
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
// Custom routes router
|
|
56
|
-
app.use(router);
|
|
57
|
-
|
|
58
|
-
// catch all router
|
|
59
|
-
app.all("*", (req, res) => {
|
|
60
|
-
res.status(404).send({
|
|
61
|
-
error: `unhandled '${req.method}' on '${req.url}'`,
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
// default error handler
|
|
66
|
-
app.use((err: Error, _req: Request, res: Response, _next: NextFunction) => {
|
|
67
|
-
// Handle authentication errors from @canva/app-middleware
|
|
68
|
-
if (err instanceof TokenVerificationError) {
|
|
69
|
-
res.status(err.statusCode).json({
|
|
70
|
-
error: err.code,
|
|
71
|
-
message: err.message,
|
|
72
|
-
});
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
console.error(err.stack);
|
|
77
|
-
res.status(500).send({
|
|
78
|
-
error: "something went wrong",
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
let server;
|
|
83
|
-
if (SHOULD_ENABLE_HTTPS) {
|
|
84
|
-
if (!HTTPS_CERT_FILE || !HTTPS_KEY_FILE) {
|
|
85
|
-
throw new Error(
|
|
86
|
-
"Looks like you're running the example with --use-https flag, but SSL certificates haven't been generated. Please remove the .ssl/ folder and re-run the command again.",
|
|
87
|
-
);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
server = https.createServer(
|
|
91
|
-
{
|
|
92
|
-
key: fs.readFileSync(HTTPS_KEY_FILE),
|
|
93
|
-
cert: fs.readFileSync(HTTPS_CERT_FILE),
|
|
94
|
-
},
|
|
95
|
-
app,
|
|
96
|
-
);
|
|
97
|
-
} else {
|
|
98
|
-
server = http.createServer(app);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
return {
|
|
102
|
-
app,
|
|
103
|
-
start: (address: number | string | undefined) => {
|
|
104
|
-
console.log(`Listening on '${address}'`);
|
|
105
|
-
server.listen(address);
|
|
106
|
-
process.on("SIGTERM", () => {
|
|
107
|
-
serverDebug("SIGTERM signal received: closing HTTP server");
|
|
108
|
-
server.close(() => {
|
|
109
|
-
serverDebug("HTTP server closed");
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
},
|
|
113
|
-
};
|
|
114
|
-
}
|