@canva/cli 0.0.1-beta.3 → 0.0.1-beta.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. package/README.md +218 -104
  2. package/cli.js +661 -394
  3. package/lib/cjs/index.cjs +5 -0
  4. package/lib/esm/index.mjs +5 -0
  5. package/package.json +19 -4
  6. package/templates/base/eslint.config.mjs +2 -27
  7. package/templates/base/package.json +31 -25
  8. package/templates/base/scripts/copy_env.ts +10 -0
  9. package/templates/base/scripts/start/app_runner.ts +39 -2
  10. package/templates/base/scripts/start/context.ts +12 -6
  11. package/templates/base/scripts/start/start.ts +11 -0
  12. package/templates/base/scripts/start/tests/start.tests.ts +61 -0
  13. package/templates/base/{webpack.config.cjs → webpack.config.ts} +46 -46
  14. package/templates/common/.cursor/mcp.json +8 -0
  15. package/templates/common/.gitignore.template +5 -6
  16. package/templates/common/.nvmrc +1 -0
  17. package/templates/common/.prettierrc +21 -0
  18. package/templates/common/.vscode/extensions.json +6 -0
  19. package/templates/common/.vscode/mcp.json +9 -0
  20. package/templates/common/README.md +4 -7
  21. package/templates/common/jest.config.mjs +29 -2
  22. package/templates/common/jest.setup.ts +20 -0
  23. package/templates/common/utils/backend/base_backend/create.ts +104 -0
  24. package/templates/common/utils/backend/jwt_middleware/index.ts +1 -0
  25. package/templates/common/utils/backend/jwt_middleware/jwt_middleware.ts +229 -0
  26. package/templates/common/utils/backend/jwt_middleware/tests/jwt_middleware.tests.ts +630 -0
  27. package/templates/common/utils/table_wrapper.ts +477 -0
  28. package/templates/common/utils/tests/table_wrapper.tests.ts +252 -0
  29. package/templates/common/utils/use_add_element.ts +48 -0
  30. package/templates/common/utils/use_feature_support.ts +28 -0
  31. package/templates/common/utils/use_overlay_hook.ts +74 -0
  32. package/templates/common/utils/use_selection_hook.ts +37 -0
  33. package/templates/dam/backend/routers/dam.ts +23 -19
  34. package/templates/dam/eslint.config.mjs +2 -28
  35. package/templates/dam/package.json +43 -39
  36. package/templates/dam/scripts/copy_env.ts +10 -0
  37. package/templates/dam/scripts/start/app_runner.ts +39 -2
  38. package/templates/dam/scripts/start/context.ts +12 -6
  39. package/templates/dam/scripts/start/start.ts +11 -0
  40. package/templates/dam/scripts/start/tests/start.tests.ts +61 -0
  41. package/templates/dam/src/app.tsx +24 -3
  42. package/templates/dam/src/config.ts +212 -87
  43. package/templates/{hello_world/webpack.config.cjs → dam/webpack.config.ts} +46 -46
  44. package/templates/data_connector/README.md +84 -0
  45. package/templates/data_connector/declarations/declarations.d.ts +29 -0
  46. package/templates/data_connector/eslint.config.mjs +14 -0
  47. package/templates/data_connector/package.json +91 -0
  48. package/templates/data_connector/scripts/copy_env.ts +10 -0
  49. package/templates/data_connector/scripts/ssl/ssl.ts +131 -0
  50. package/templates/data_connector/scripts/start/app_runner.ts +201 -0
  51. package/templates/data_connector/scripts/start/context.ts +171 -0
  52. package/templates/data_connector/scripts/start/start.ts +46 -0
  53. package/templates/data_connector/scripts/start/tests/start.tests.ts +61 -0
  54. package/templates/data_connector/src/api/connect_client.ts +6 -0
  55. package/templates/data_connector/src/api/data_source.ts +96 -0
  56. package/templates/data_connector/src/api/data_sources/designs.tsx +296 -0
  57. package/templates/data_connector/src/api/data_sources/index.ts +4 -0
  58. package/templates/data_connector/src/api/data_sources/templates.tsx +329 -0
  59. package/templates/data_connector/src/api/fetch_data_table.ts +55 -0
  60. package/templates/data_connector/src/api/index.ts +4 -0
  61. package/templates/data_connector/src/api/oauth.ts +8 -0
  62. package/templates/data_connector/src/api/tests/data_source.test.tsx +99 -0
  63. package/templates/data_connector/src/app.tsx +20 -0
  64. package/templates/data_connector/src/components/app_error.tsx +15 -0
  65. package/templates/data_connector/src/components/footer.tsx +26 -0
  66. package/templates/data_connector/src/components/header.tsx +40 -0
  67. package/templates/data_connector/src/components/index.ts +3 -0
  68. package/templates/data_connector/src/components/inputs/messages.tsx +99 -0
  69. package/templates/data_connector/src/components/inputs/search_filter.tsx +108 -0
  70. package/templates/data_connector/src/components/inputs/select_field.tsx +26 -0
  71. package/templates/data_connector/src/context/app_context.tsx +124 -0
  72. package/templates/data_connector/src/context/index.ts +2 -0
  73. package/templates/data_connector/src/context/use_app_context.ts +17 -0
  74. package/templates/data_connector/src/entrypoint.tsx +70 -0
  75. package/templates/data_connector/src/home.tsx +21 -0
  76. package/templates/data_connector/src/index.tsx +69 -0
  77. package/templates/data_connector/src/pages/data_source_config.tsx +9 -0
  78. package/templates/data_connector/src/pages/error.tsx +37 -0
  79. package/templates/data_connector/src/pages/index.ts +4 -0
  80. package/templates/data_connector/src/pages/login.tsx +145 -0
  81. package/templates/data_connector/src/pages/select_source.tsx +24 -0
  82. package/templates/data_connector/src/routes/index.ts +2 -0
  83. package/templates/data_connector/src/routes/protected_route.tsx +25 -0
  84. package/templates/data_connector/src/routes/routes.tsx +46 -0
  85. package/templates/data_connector/src/utils/data_params.ts +17 -0
  86. package/templates/data_connector/src/utils/data_table.ts +115 -0
  87. package/templates/data_connector/src/utils/fetch_result.ts +36 -0
  88. package/templates/data_connector/src/utils/index.ts +2 -0
  89. package/templates/data_connector/src/utils/tests/data_table.test.ts +133 -0
  90. package/templates/data_connector/styles/components.css +38 -0
  91. package/templates/data_connector/tsconfig.json +54 -0
  92. package/templates/{gen_ai/webpack.config.cjs → data_connector/webpack.config.ts} +46 -46
  93. package/templates/gen_ai/README.md +1 -40
  94. package/templates/gen_ai/backend/routers/image.ts +11 -11
  95. package/templates/gen_ai/backend/server.ts +0 -7
  96. package/templates/gen_ai/eslint.config.mjs +2 -27
  97. package/templates/gen_ai/package.json +48 -42
  98. package/templates/gen_ai/scripts/copy_env.ts +10 -0
  99. package/templates/gen_ai/scripts/start/app_runner.ts +39 -2
  100. package/templates/gen_ai/scripts/start/context.ts +12 -6
  101. package/templates/gen_ai/scripts/start/start.ts +11 -0
  102. package/templates/gen_ai/scripts/start/tests/start.tests.ts +61 -0
  103. package/templates/gen_ai/src/api/api.ts +24 -79
  104. package/templates/gen_ai/src/app.tsx +16 -10
  105. package/templates/gen_ai/src/components/footer.messages.ts +0 -5
  106. package/templates/gen_ai/src/components/footer.tsx +7 -25
  107. package/templates/gen_ai/src/components/index.ts +0 -1
  108. package/templates/gen_ai/src/components/loading_results.tsx +4 -8
  109. package/templates/gen_ai/src/components/tests/remaining_credit.tests.tsx +43 -0
  110. package/templates/gen_ai/src/context/app_context.tsx +5 -33
  111. package/templates/gen_ai/src/context/context.messages.ts +1 -12
  112. package/templates/gen_ai/src/home.tsx +13 -0
  113. package/templates/gen_ai/src/index.tsx +2 -18
  114. package/templates/gen_ai/src/routes/routes.tsx +2 -2
  115. package/templates/{dam/webpack.config.cjs → gen_ai/webpack.config.ts} +46 -46
  116. package/templates/hello_world/eslint.config.mjs +2 -27
  117. package/templates/hello_world/package.json +47 -34
  118. package/templates/hello_world/scripts/copy_env.ts +10 -0
  119. package/templates/hello_world/scripts/start/app_runner.ts +39 -2
  120. package/templates/hello_world/scripts/start/context.ts +12 -6
  121. package/templates/hello_world/scripts/start/start.ts +11 -0
  122. package/templates/hello_world/scripts/start/tests/start.tests.ts +61 -0
  123. package/templates/hello_world/src/app.tsx +20 -0
  124. package/templates/hello_world/src/tests/__snapshots__/app.tests.tsx.snap +45 -0
  125. package/templates/hello_world/src/tests/app.tests.tsx +86 -0
  126. package/templates/hello_world/webpack.config.ts +270 -0
  127. package/templates/common/conf/eslint-general.mjs +0 -277
  128. package/templates/common/conf/eslint-i18n.mjs +0 -23
  129. package/templates/gen_ai/backend/routers/oauth.ts +0 -393
  130. package/templates/gen_ai/src/components/logged_in_status.tsx +0 -44
  131. package/templates/gen_ai/src/services/auth.tsx +0 -26
  132. package/templates/gen_ai/src/services/index.ts +0 -1
@@ -0,0 +1,86 @@
1
+ /* eslint-disable formatjs/no-literal-string-in-jsx */
2
+ import React from "react";
3
+ import type { RenderResult } from "@testing-library/react";
4
+ import { fireEvent, render } from "@testing-library/react";
5
+ import { TestAppI18nProvider } from "@canva/app-i18n-kit";
6
+ import { TestAppUiProvider } from "@canva/app-ui-kit";
7
+ import { requestOpenExternalUrl } from "@canva/platform";
8
+ import { useAddElement } from "utils/use_add_element";
9
+ import { App, DOCS_URL } from "../app";
10
+
11
+ function renderInTestProvider(node: React.ReactNode): RenderResult {
12
+ return render(
13
+ // In a test environment, you should wrap your apps in `TestAppI18nProvider` and `TestAppUiProvider`, rather than `AppI18nProvider` and `AppUiProvider`
14
+ <TestAppI18nProvider>
15
+ <TestAppUiProvider>{node}</TestAppUiProvider>,
16
+ </TestAppI18nProvider>,
17
+ );
18
+ }
19
+
20
+ jest.mock("utils/use_add_element");
21
+
22
+ // This test demonstrates how to test code that uses functions from the Canva Apps SDK
23
+ // For more information on testing with the Canva Apps SDK, see https://www.canva.dev/docs/apps/testing/
24
+ describe("Hello World Tests", () => {
25
+ // Mocking the useAddElement hook
26
+ const mockAddElement = jest.fn();
27
+ const mockAddUseElement = jest.mocked(useAddElement);
28
+ const mockRequestOpenExternalUrl = jest.mocked(requestOpenExternalUrl);
29
+
30
+ beforeEach(() => {
31
+ jest.resetAllMocks();
32
+ mockAddUseElement.mockReturnValue(mockAddElement);
33
+ mockRequestOpenExternalUrl.mockResolvedValue({ status: "completed" });
34
+ });
35
+
36
+ // this test uses a mock in place of the useAddElement hook
37
+ it("should add a text element when the button is clicked", () => {
38
+ // assert that the mocks are in the expected clean state
39
+ expect(mockAddUseElement).not.toHaveBeenCalled();
40
+ expect(mockAddElement).not.toHaveBeenCalled();
41
+
42
+ const result = renderInTestProvider(<App />);
43
+
44
+ // the hook should have been called in the render process but not the callback
45
+ expect(mockAddUseElement).toHaveBeenCalled();
46
+ expect(mockAddElement).not.toHaveBeenCalled();
47
+
48
+ // get a reference to the do something cool button element
49
+ const doSomethingCoolBtn = result.getByRole("button", {
50
+ name: "Do something cool",
51
+ });
52
+
53
+ // programmatically simulate clicking the button
54
+ fireEvent.click(doSomethingCoolBtn);
55
+
56
+ // we expect that addElement has been called by the button's click handler
57
+ expect(mockAddElement).toHaveBeenCalled();
58
+ });
59
+
60
+ // this test uses a mock in place of the @canva/platform requestOpenExternalUrl function
61
+ it("should call `requestOpenExternalUrl` when the button is clicked", () => {
62
+ expect(mockRequestOpenExternalUrl).not.toHaveBeenCalled();
63
+
64
+ const result = renderInTestProvider(<App />);
65
+
66
+ // get a reference to the Apps SDK button by name
67
+ const sdkButton = result.getByRole("button", {
68
+ name: "Open Canva Apps SDK docs",
69
+ });
70
+
71
+ expect(mockRequestOpenExternalUrl).not.toHaveBeenCalled();
72
+ fireEvent.click(sdkButton);
73
+ expect(mockRequestOpenExternalUrl).toHaveBeenCalled();
74
+
75
+ // assert that the requestOpenExternalUrl function was called with the expected arguments
76
+ expect(mockRequestOpenExternalUrl.mock.calls[0][0]).toEqual({
77
+ url: DOCS_URL,
78
+ });
79
+ });
80
+
81
+ // this test demonstrates the use of a snapshot test
82
+ it("should have a consistent snapshot", () => {
83
+ const result = renderInTestProvider(<App />);
84
+ expect(result.container).toMatchSnapshot();
85
+ });
86
+ });
@@ -0,0 +1,270 @@
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";
9
+
10
+ config();
11
+
12
+ type DevConfig = {
13
+ port: number;
14
+ enableHmr: boolean;
15
+ enableHttps: boolean;
16
+ appOrigin?: string;
17
+ appId?: string; // Deprecated in favour of appOrigin
18
+ certFile?: string;
19
+ keyFile?: string;
20
+ };
21
+
22
+ export function buildConfig({
23
+ devConfig,
24
+ appEntry = path.join(process.cwd(), "src", "index.tsx"),
25
+ backendHost = process.env.CANVA_BACKEND_HOST,
26
+ // For IN_HARNESS, refer to the following docs for more information: https://www.canva.dev/docs/apps/test-harness/
27
+ inHarness = process.env.IN_HARNESS === "true",
28
+ }: {
29
+ devConfig?: DevConfig;
30
+ appEntry?: string;
31
+ backendHost?: string;
32
+ inHarness?: boolean;
33
+ } = {}): Configuration & DevServerConfiguration {
34
+ const mode = devConfig ? "development" : "production";
35
+
36
+ if (!backendHost) {
37
+ console.error(
38
+ chalk.redBright.bold("BACKEND_HOST is undefined."),
39
+ `Refer to "Customizing the backend host" in the README.md for more information.`,
40
+ );
41
+ process.exit(-1);
42
+ } else if (backendHost.includes("localhost") && mode === "production") {
43
+ console.error(
44
+ chalk.redBright.bold(
45
+ "BACKEND_HOST should not be set to localhost for production builds!",
46
+ ),
47
+ `Refer to "Customizing the backend host" in the README.md for more information.`,
48
+ );
49
+ }
50
+
51
+ return {
52
+ mode,
53
+ context: path.resolve(process.cwd(), "./"),
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
+ },
62
+ target: "web",
63
+ resolve: {
64
+ alias: {
65
+ assets: path.resolve(process.cwd(), "assets"),
66
+ utils: path.resolve(process.cwd(), "utils"),
67
+ styles: path.resolve(process.cwd(), "styles"),
68
+ src: path.resolve(process.cwd(), "src"),
69
+ },
70
+ extensions: [".ts", ".tsx", ".js", ".css", ".svg", ".woff", ".woff2"],
71
+ },
72
+ infrastructureLogging: {
73
+ level: inHarness ? "info" : "none",
74
+ },
75
+ module: {
76
+ rules: [
77
+ {
78
+ test: /\.tsx?$/,
79
+ exclude: /node_modules/,
80
+ use: [
81
+ {
82
+ loader: "ts-loader",
83
+ options: {
84
+ transpileOnly: true,
85
+ getCustomTransformers() {
86
+ return {
87
+ before: [
88
+ transform({
89
+ overrideIdFn: "[sha512:contenthash:base64:6]",
90
+ }),
91
+ ],
92
+ };
93
+ },
94
+ },
95
+ },
96
+ ],
97
+ },
98
+ {
99
+ test: /\.css$/,
100
+ exclude: /node_modules/,
101
+ use: [
102
+ "style-loader",
103
+ {
104
+ loader: "css-loader",
105
+ options: {
106
+ modules: true,
107
+ },
108
+ },
109
+ {
110
+ loader: "postcss-loader",
111
+ options: {
112
+ postcssOptions: {
113
+ plugins: [require("cssnano")({ preset: "default" })],
114
+ },
115
+ },
116
+ },
117
+ ],
118
+ },
119
+ {
120
+ test: /\.(png|jpg|jpeg)$/i,
121
+ type: "asset/inline",
122
+ },
123
+ {
124
+ test: /\.(woff|woff2)$/,
125
+ type: "asset/inline",
126
+ },
127
+ {
128
+ test: /\.svg$/,
129
+ oneOf: [
130
+ {
131
+ issuer: /\.[jt]sx?$/,
132
+ resourceQuery: /react/, // *.svg?react
133
+ use: ["@svgr/webpack", "url-loader"],
134
+ },
135
+ {
136
+ type: "asset/resource",
137
+ parser: {
138
+ dataUrlCondition: {
139
+ maxSize: 200,
140
+ },
141
+ },
142
+ },
143
+ ],
144
+ },
145
+ {
146
+ test: /\.css$/,
147
+ include: /node_modules/,
148
+ use: [
149
+ "style-loader",
150
+ "css-loader",
151
+ {
152
+ loader: "postcss-loader",
153
+ options: {
154
+ postcssOptions: {
155
+ plugins: [require("cssnano")({ preset: "default" })],
156
+ },
157
+ },
158
+ },
159
+ ],
160
+ },
161
+ ],
162
+ },
163
+ optimization: {
164
+ minimizer: [
165
+ new TerserPlugin({
166
+ terserOptions: {
167
+ format: {
168
+ // Turned on because emoji and regex is not minified properly using default
169
+ // https://github.com/facebook/create-react-app/issues/2488
170
+ ascii_only: true,
171
+ },
172
+ },
173
+ }),
174
+ ],
175
+ },
176
+ output: {
177
+ filename: `[name].js`,
178
+ path: path.resolve(process.cwd(), "dist"),
179
+ clean: true,
180
+ },
181
+ plugins: [
182
+ new DefinePlugin({
183
+ BACKEND_HOST: JSON.stringify(backendHost),
184
+ }),
185
+ // Apps can only submit a single JS file via the developer portal
186
+ new optimize.LimitChunkCountPlugin({ maxChunks: 1 }),
187
+ ].filter(Boolean),
188
+ ...buildDevConfig(devConfig),
189
+ };
190
+ }
191
+
192
+ function buildDevConfig(options?: DevConfig): {
193
+ devtool?: string;
194
+ devServer?: DevServerConfiguration;
195
+ } {
196
+ if (!options) {
197
+ return {};
198
+ }
199
+
200
+ const { port, enableHmr, appOrigin, appId, enableHttps, certFile, keyFile } =
201
+ options;
202
+
203
+ let devServer: DevServerConfiguration = {
204
+ server: enableHttps
205
+ ? {
206
+ type: "https",
207
+ options: {
208
+ cert: certFile,
209
+ key: keyFile,
210
+ },
211
+ }
212
+ : "http",
213
+ host: "localhost",
214
+ historyApiFallback: {
215
+ rewrites: [{ from: /^\/$/, to: "/app.js" }],
216
+ },
217
+ port,
218
+ client: {
219
+ logging: "verbose",
220
+ },
221
+ static: {
222
+ directory: path.resolve(process.cwd(), "assets"),
223
+ publicPath: "/assets",
224
+ },
225
+ };
226
+
227
+ if (enableHmr && appOrigin) {
228
+ devServer = {
229
+ ...devServer,
230
+ allowedHosts: new URL(appOrigin).hostname,
231
+ headers: {
232
+ "Access-Control-Allow-Origin": appOrigin,
233
+ "Access-Control-Allow-Credentials": "true",
234
+ "Access-Control-Allow-Private-Network": "true",
235
+ },
236
+ };
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
+ } else {
256
+ if (enableHmr && !appOrigin) {
257
+ console.warn(
258
+ "Attempted to enable Hot Module Replacement (HMR) without configuring App Origin... Disabling HMR.",
259
+ );
260
+ }
261
+ devServer.webSocketServer = false;
262
+ }
263
+
264
+ return {
265
+ devtool: "source-map",
266
+ devServer,
267
+ };
268
+ }
269
+
270
+ export default buildConfig;
@@ -1,277 +0,0 @@
1
- import typescriptEslint from "@typescript-eslint/eslint-plugin";
2
- import jest from "eslint-plugin-jest";
3
- import react from "eslint-plugin-react";
4
- import globals from "globals";
5
-
6
- export default [
7
- {
8
- plugins: {
9
- "@typescript-eslint": typescriptEslint,
10
- jest,
11
- react,
12
- },
13
- languageOptions: {
14
- globals: {
15
- ...globals.serviceworker,
16
- ...globals.browser,
17
- },
18
- },
19
- settings: {
20
- react: {
21
- version: "detect",
22
- },
23
- },
24
- rules: {
25
- "@typescript-eslint/no-non-null-assertion": "warn",
26
- "@typescript-eslint/no-empty-function": "off",
27
- "@typescript-eslint/consistent-type-imports": "error",
28
- "@typescript-eslint/no-explicit-any": "warn",
29
- "@typescript-eslint/no-empty-interface": "warn",
30
- "@typescript-eslint/consistent-type-definitions": "off",
31
- "@typescript-eslint/explicit-member-accessibility": [
32
- "error",
33
- {
34
- accessibility: "no-public",
35
- overrides: {
36
- parameterProperties: "off",
37
- },
38
- },
39
- ],
40
- "@typescript-eslint/naming-convention": [
41
- "error",
42
- {
43
- selector: "typeLike",
44
- format: ["PascalCase"],
45
- leadingUnderscore: "allow",
46
- },
47
- ],
48
- "no-invalid-this": "off",
49
- "@typescript-eslint/no-invalid-this": "error",
50
- "@typescript-eslint/no-unused-expressions": [
51
- "error",
52
- {
53
- allowShortCircuit: true,
54
- allowTernary: true,
55
- },
56
- ],
57
- "no-unused-vars": "off",
58
- "@typescript-eslint/no-unused-vars": [
59
- "error",
60
- {
61
- vars: "all",
62
- varsIgnorePattern: "^_",
63
- args: "none",
64
- ignoreRestSiblings: true,
65
- },
66
- ],
67
- "@typescript-eslint/no-require-imports": "error",
68
- "jest/no-restricted-matchers": [
69
- "error",
70
- {
71
- toContainElement:
72
- "toContainElement is not recommended as it encourages testing the internals of the components",
73
- toContainHTML:
74
- "toContainHTML is not recommended as it encourages testing the internals of the components",
75
- toHaveAttribute:
76
- "toHaveAttribute is not recommended as it encourages testing the internals of the components",
77
- toHaveClass:
78
- "toHaveClass is not recommended as it encourages testing the internals of the components",
79
- toHaveStyle:
80
- "toHaveStyle is not recommended as it encourages testing the internals of the components",
81
- },
82
- ],
83
- "react/jsx-curly-brace-presence": [
84
- "error",
85
- {
86
- props: "never",
87
- children: "never",
88
- },
89
- ],
90
- "react/jsx-tag-spacing": [
91
- "error",
92
- {
93
- closingSlash: "never",
94
- beforeSelfClosing: "allow",
95
- afterOpening: "never",
96
- beforeClosing: "allow",
97
- },
98
- ],
99
- "react/self-closing-comp": "error",
100
- "react/no-unescaped-entities": "off",
101
- "react/jsx-uses-react": "off",
102
- "react/react-in-jsx-scope": "off",
103
- "default-case": "error",
104
- eqeqeq: [
105
- "error",
106
- "always",
107
- {
108
- null: "never",
109
- },
110
- ],
111
- "no-caller": "error",
112
- "no-console": "error",
113
- "no-eval": "error",
114
- "no-inner-declarations": "error",
115
- "no-new-wrappers": "error",
116
- "no-restricted-globals": [
117
- "error",
118
- {
119
- name: "fit",
120
- message: "Don't focus tests",
121
- },
122
- {
123
- name: "fdescribe",
124
- message: "Don't focus tests",
125
- },
126
- {
127
- name: "length",
128
- message:
129
- "Undefined length - Did you mean to use window.length instead?",
130
- },
131
- {
132
- name: "name",
133
- message: "Undefined name - Did you mean to use window.name instead?",
134
- },
135
- {
136
- name: "status",
137
- message:
138
- "Undefined status - Did you mean to use window.status instead?",
139
- },
140
- {
141
- name: "spyOn",
142
- message: "Don't use spyOn directly, use jest.spyOn",
143
- },
144
- ],
145
- "no-restricted-properties": [
146
- "error",
147
- {
148
- property: "bind",
149
- message: "Don't o.f.bind(o, ...), use () => o.f(...)",
150
- },
151
- {
152
- object: "ReactDOM",
153
- property: "findDOMNode",
154
- message: "Don't use ReactDOM.findDOMNode() as it is deprecated",
155
- },
156
- ],
157
- "no-restricted-syntax": [
158
- "error",
159
- {
160
- selector: "AccessorProperty, TSAbstractAccessorProperty",
161
- message:
162
- "Accessor property syntax is not allowed, use getter and setters.",
163
- },
164
- {
165
- selector: "PrivateIdentifier",
166
- message:
167
- "Private identifiers are not allowed, use TypeScript private fields.",
168
- },
169
- {
170
- selector:
171
- "JSXOpeningElement[name.name = /^[A-Z]/] > JSXAttribute[name.name = /-/]",
172
- message:
173
- "Passing hyphenated props to custom components is not type-safe. Prefer a camelCased equivalent if available. (See https://github.com/microsoft/TypeScript/issues/55182)",
174
- },
175
- {
176
- selector:
177
- "CallExpression[callee.object.name='window'][callee.property.name='open']",
178
- message:
179
- "Apps are currently not allowed to open popups, or new tabs via browser APIs. Please use `requestOpenExternalUrl` from `@canva/platform` to link to external URLs. To learn more, see https://www.canva.dev/docs/apps/api/platform-request-open-external-url/",
180
- },
181
- ],
182
- "no-return-await": "error",
183
- "no-throw-literal": "error",
184
- "no-undef-init": "error",
185
- "no-var": "error",
186
- "object-shorthand": "error",
187
- "prefer-const": [
188
- "error",
189
- {
190
- destructuring: "all",
191
- },
192
- ],
193
- "prefer-object-spread": "error",
194
- "prefer-rest-params": "error",
195
- "prefer-spread": "error",
196
- radix: "error",
197
- },
198
- },
199
- {
200
- files: ["**/*.tsx"],
201
- rules: {
202
- "react/no-deprecated": "error",
203
- "react/forbid-elements": [
204
- "error",
205
- {
206
- forbid: [
207
- {
208
- element: "video",
209
- message:
210
- "Don't use HTML video directly. Instead, use the App UI Kit <VideoCard /> as this respects users' auto-playing preferences",
211
- },
212
- {
213
- element: "em",
214
- message:
215
- "Don't use <em> to italicize text. Canva's UI fonts don't support italic font style.",
216
- },
217
- {
218
- element: "i",
219
- message:
220
- "Don't use <i> to italicize text. Canva's UI fonts don't support italic font style.",
221
- },
222
- {
223
- element: "iframe",
224
- message:
225
- "Canva Apps aren't allowed to contain iframes. You should either recreate the UI you want to show in the iframe in the app directly, or link to your page via a `<Link>` tag. For more info see https://www.canva.dev/docs/apps/content-security-policy/#what-is-and-isnt-allowed",
226
- },
227
- {
228
- element: "script",
229
- message:
230
- "Script tags are not allowed in Canva SDK Apps. You should import JavaScript modules instead. For more info see https://www.canva.dev/docs/apps/content-security-policy/#what-is-and-isnt-allowed",
231
- },
232
- {
233
- element: "a",
234
- message:
235
- "Don't use <a> tags. Instead, use the <Link> component from the App UI Kit, and remember to open the url via the requestOpenExternalUrl method from @canva/platform.",
236
- },
237
- {
238
- element: "img",
239
- message:
240
- "Have you considered using <ImageCard /> from the App UI Kit instead?",
241
- },
242
- {
243
- element: "embed",
244
- message:
245
- "Have you considered using <EmbedCard /> from the App UI Kit instead?",
246
- },
247
- {
248
- element: "audio",
249
- message:
250
- "Have you considered using <AudioCard /> from the App UI Kit instead?",
251
- },
252
- {
253
- element: "button",
254
- message:
255
- "Rather than using the native HTML <button> element, use the <Button> component from the App UI Kit for consistency and accessibility.",
256
- },
257
- {
258
- element: "input",
259
- message:
260
- "Wherever possible, prefer using the form inputs from the App UI Kit for consistency and accessibility (TextInput, Checkbox, FileInput, etc).",
261
- },
262
- {
263
- element: "base",
264
- message:
265
- "The <base> tag is not supported in Canva Apps. We recommend using hash-based routing. For more on what is and isn't allowed in Canva Apps see https://www.canva.dev/docs/apps/content-security-policy/#what-is-and-isnt-allowed",
266
- },
267
- {
268
- element: "link",
269
- message:
270
- "If you're trying to include a css stylesheet, we recommend importing css using React, or using embedded stylesheets. For more on what is and isn't allowed in Canva Apps see https://www.canva.dev/docs/apps/content-security-policy/#what-is-and-isnt-allowed",
271
- },
272
- ],
273
- },
274
- ],
275
- },
276
- },
277
- ];
@@ -1,23 +0,0 @@
1
- import formatjs from "eslint-plugin-formatjs";
2
-
3
- export default [
4
- {
5
- plugins: {
6
- formatjs,
7
- },
8
- rules: {
9
- "formatjs/no-invalid-icu": "error",
10
- "formatjs/no-literal-string-in-jsx": "error",
11
- "formatjs/enforce-description": "error",
12
- "formatjs/enforce-default-message": "error",
13
- "formatjs/enforce-placeholders": "error",
14
- "formatjs/no-id": "error",
15
- "formatjs/no-emoji": "error",
16
- "formatjs/no-useless-message": "error",
17
- "formatjs/no-multiple-plurals": "error",
18
- "formatjs/no-offset": "error",
19
- "formatjs/blocklist-elements": [2, ["selectordinal"]],
20
- "formatjs/no-complex-selectors": "error",
21
- }
22
- }
23
- ];