@canva/cli 0.0.1-beta.1 → 0.0.1-beta.11
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 +184 -108
- package/cli.js +446 -359
- package/lib/cjs/index.cjs +392 -0
- package/lib/esm/index.esm +392 -0
- package/package.json +11 -2
- package/templates/base/backend/routers/oauth.ts +393 -0
- package/templates/base/eslint.config.mjs +5 -277
- package/templates/base/package.json +26 -23
- package/templates/base/scripts/copy-env.ts +10 -0
- package/templates/base/utils/backend/bearer_middleware/bearer_middleware.ts +101 -0
- package/templates/base/utils/backend/bearer_middleware/index.ts +1 -0
- package/templates/base/utils/backend/bearer_middleware/tests/bearer_middleware.tests.ts +192 -0
- package/templates/base/utils/use_add_element.ts +48 -0
- package/templates/base/utils/use_feature_support.ts +28 -0
- package/templates/base/webpack.config.cjs +3 -1
- package/templates/common/.gitignore.template +5 -6
- package/templates/common/.nvmrc +1 -0
- package/templates/common/.prettierrc +21 -0
- package/templates/common/.vscode/extensions.json +6 -0
- package/templates/common/README.md +4 -74
- package/templates/common/conf/eslint-general.mjs +303 -0
- package/templates/common/conf/eslint-i18n.mjs +41 -0
- package/templates/common/conf/eslint-local-i18n-rules/index.mjs +181 -0
- package/templates/common/jest.config.mjs +29 -2
- package/templates/common/jest.setup.ts +19 -0
- package/templates/common/utils/backend/base_backend/create.ts +104 -0
- package/templates/common/utils/table_wrapper.ts +477 -0
- package/templates/common/utils/tests/table_wrapper.tests.ts +252 -0
- package/templates/common/utils/use_add_element.ts +48 -0
- package/templates/common/utils/use_feature_support.ts +28 -0
- package/templates/common/utils/use_overlay_hook.ts +74 -0
- package/templates/common/utils/use_selection_hook.ts +37 -0
- package/templates/dam/backend/server.ts +0 -7
- package/templates/dam/eslint.config.mjs +6 -275
- package/templates/dam/package.json +43 -35
- package/templates/dam/scripts/copy-env.ts +10 -0
- package/templates/dam/src/app.tsx +2 -135
- package/templates/dam/webpack.config.cjs +3 -1
- package/templates/gen_ai/README.md +1 -1
- package/templates/gen_ai/backend/routers/image.ts +3 -3
- package/templates/gen_ai/backend/server.ts +0 -7
- package/templates/gen_ai/eslint.config.mjs +5 -277
- package/templates/gen_ai/package.json +46 -38
- package/templates/gen_ai/scripts/copy-env.ts +10 -0
- package/templates/gen_ai/src/api/api.ts +1 -39
- package/templates/gen_ai/src/app.tsx +16 -10
- package/templates/gen_ai/src/components/footer.messages.ts +0 -5
- package/templates/gen_ai/src/components/footer.tsx +2 -16
- package/templates/gen_ai/src/components/image_grid.tsx +9 -7
- package/templates/gen_ai/src/components/index.ts +0 -1
- package/templates/gen_ai/src/components/prompt_input.tsx +2 -0
- package/templates/gen_ai/src/components/tests/remaining_credit.tests.tsx +43 -0
- package/templates/gen_ai/src/context/app_context.tsx +4 -26
- package/templates/gen_ai/src/context/context.messages.ts +1 -12
- package/templates/gen_ai/src/home.tsx +13 -0
- package/templates/gen_ai/src/index.tsx +2 -18
- package/templates/gen_ai/src/routes/routes.tsx +2 -2
- package/templates/gen_ai/utils/backend/bearer_middleware/bearer_middleware.ts +101 -0
- package/templates/gen_ai/utils/backend/bearer_middleware/index.ts +1 -0
- package/templates/gen_ai/utils/backend/bearer_middleware/tests/bearer_middleware.tests.ts +192 -0
- package/templates/gen_ai/webpack.config.cjs +3 -1
- package/templates/hello_world/eslint.config.mjs +5 -277
- package/templates/hello_world/package.json +46 -28
- package/templates/hello_world/scripts/copy-env.ts +10 -0
- package/templates/hello_world/src/app.tsx +25 -3
- 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 +48 -0
- package/templates/hello_world/utils/use_feature_support.ts +28 -0
- package/templates/hello_world/webpack.config.cjs +3 -1
- package/templates/dam/backend/database/database.ts +0 -42
- package/templates/dam/backend/routers/auth.ts +0 -285
- package/templates/gen_ai/backend/routers/auth.ts +0 -285
- package/templates/gen_ai/src/components/logged_in_status.tsx +0 -44
- package/templates/gen_ai/src/services/auth.tsx +0 -31
- package/templates/gen_ai/src/services/index.ts +0 -1
- /package/templates/{gen_ai → common}/utils/backend/jwt_middleware/index.ts +0 -0
- /package/templates/{gen_ai → common}/utils/backend/jwt_middleware/jwt_middleware.ts +0 -0
- /package/templates/{gen_ai → common}/utils/backend/jwt_middleware/tests/jwt_middleware.tests.ts +0 -0
|
@@ -1,11 +1,9 @@
|
|
|
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
1
|
import path from "node:path";
|
|
6
2
|
import { fileURLToPath } from "node:url";
|
|
7
3
|
import js from "@eslint/js";
|
|
8
4
|
import { FlatCompat } from "@eslint/eslintrc";
|
|
5
|
+
import general from "./conf/eslint-general.mjs";
|
|
6
|
+
// import i18n from "./conf/eslint-i18n.mjs";
|
|
9
7
|
|
|
10
8
|
const __filename = fileURLToPath(import.meta.url);
|
|
11
9
|
const __dirname = path.dirname(__filename);
|
|
@@ -34,276 +32,9 @@ export default [
|
|
|
34
32
|
"plugin:@typescript-eslint/strict",
|
|
35
33
|
"plugin:@typescript-eslint/stylistic",
|
|
36
34
|
"plugin:react/recommended",
|
|
37
|
-
"plugin:jest/recommended"
|
|
35
|
+
"plugin:jest/recommended",
|
|
38
36
|
),
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
jest,
|
|
43
|
-
react,
|
|
44
|
-
},
|
|
45
|
-
languageOptions: {
|
|
46
|
-
globals: {
|
|
47
|
-
...globals.serviceworker,
|
|
48
|
-
...globals.browser,
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
settings: {
|
|
52
|
-
react: {
|
|
53
|
-
version: "detect",
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
rules: {
|
|
57
|
-
"@typescript-eslint/no-non-null-assertion": "warn",
|
|
58
|
-
"@typescript-eslint/no-empty-function": "off",
|
|
59
|
-
"@typescript-eslint/consistent-type-imports": "error",
|
|
60
|
-
"@typescript-eslint/no-explicit-any": "warn",
|
|
61
|
-
"@typescript-eslint/no-empty-interface": "warn",
|
|
62
|
-
"@typescript-eslint/consistent-type-definitions": "off",
|
|
63
|
-
"@typescript-eslint/explicit-member-accessibility": [
|
|
64
|
-
"error",
|
|
65
|
-
{
|
|
66
|
-
accessibility: "no-public",
|
|
67
|
-
overrides: {
|
|
68
|
-
parameterProperties: "off",
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
],
|
|
72
|
-
"@typescript-eslint/naming-convention": [
|
|
73
|
-
"error",
|
|
74
|
-
{
|
|
75
|
-
selector: "typeLike",
|
|
76
|
-
format: ["PascalCase"],
|
|
77
|
-
leadingUnderscore: "allow",
|
|
78
|
-
},
|
|
79
|
-
],
|
|
80
|
-
"no-invalid-this": "off",
|
|
81
|
-
"@typescript-eslint/no-invalid-this": "error",
|
|
82
|
-
"@typescript-eslint/no-unused-expressions": [
|
|
83
|
-
"error",
|
|
84
|
-
{
|
|
85
|
-
allowShortCircuit: true,
|
|
86
|
-
allowTernary: true,
|
|
87
|
-
},
|
|
88
|
-
],
|
|
89
|
-
"no-unused-vars": "off",
|
|
90
|
-
"@typescript-eslint/no-unused-vars": [
|
|
91
|
-
"error",
|
|
92
|
-
{
|
|
93
|
-
vars: "all",
|
|
94
|
-
varsIgnorePattern: "^_",
|
|
95
|
-
args: "none",
|
|
96
|
-
ignoreRestSiblings: true,
|
|
97
|
-
},
|
|
98
|
-
],
|
|
99
|
-
"@typescript-eslint/no-require-imports": "error",
|
|
100
|
-
"jest/no-restricted-matchers": [
|
|
101
|
-
"error",
|
|
102
|
-
{
|
|
103
|
-
toContainElement:
|
|
104
|
-
"toContainElement is not recommended as it encourages testing the internals of the components",
|
|
105
|
-
toContainHTML:
|
|
106
|
-
"toContainHTML is not recommended as it encourages testing the internals of the components",
|
|
107
|
-
toHaveAttribute:
|
|
108
|
-
"toHaveAttribute is not recommended as it encourages testing the internals of the components",
|
|
109
|
-
toHaveClass:
|
|
110
|
-
"toHaveClass is not recommended as it encourages testing the internals of the components",
|
|
111
|
-
toHaveStyle:
|
|
112
|
-
"toHaveStyle is not recommended as it encourages testing the internals of the components",
|
|
113
|
-
},
|
|
114
|
-
],
|
|
115
|
-
"react/jsx-curly-brace-presence": [
|
|
116
|
-
"error",
|
|
117
|
-
{
|
|
118
|
-
props: "never",
|
|
119
|
-
children: "never",
|
|
120
|
-
},
|
|
121
|
-
],
|
|
122
|
-
"react/jsx-tag-spacing": [
|
|
123
|
-
"error",
|
|
124
|
-
{
|
|
125
|
-
closingSlash: "never",
|
|
126
|
-
beforeSelfClosing: "allow",
|
|
127
|
-
afterOpening: "never",
|
|
128
|
-
beforeClosing: "allow",
|
|
129
|
-
},
|
|
130
|
-
],
|
|
131
|
-
"react/self-closing-comp": "error",
|
|
132
|
-
"react/no-unescaped-entities": "off",
|
|
133
|
-
"react/jsx-uses-react": "off",
|
|
134
|
-
"react/react-in-jsx-scope": "off",
|
|
135
|
-
"default-case": "error",
|
|
136
|
-
eqeqeq: [
|
|
137
|
-
"error",
|
|
138
|
-
"always",
|
|
139
|
-
{
|
|
140
|
-
null: "never",
|
|
141
|
-
},
|
|
142
|
-
],
|
|
143
|
-
"no-caller": "error",
|
|
144
|
-
"no-console": "error",
|
|
145
|
-
"no-eval": "error",
|
|
146
|
-
"no-inner-declarations": "error",
|
|
147
|
-
"no-new-wrappers": "error",
|
|
148
|
-
"no-restricted-globals": [
|
|
149
|
-
"error",
|
|
150
|
-
{
|
|
151
|
-
name: "fit",
|
|
152
|
-
message: "Don't focus tests",
|
|
153
|
-
},
|
|
154
|
-
{
|
|
155
|
-
name: "fdescribe",
|
|
156
|
-
message: "Don't focus tests",
|
|
157
|
-
},
|
|
158
|
-
{
|
|
159
|
-
name: "length",
|
|
160
|
-
message:
|
|
161
|
-
"Undefined length - Did you mean to use window.length instead?",
|
|
162
|
-
},
|
|
163
|
-
{
|
|
164
|
-
name: "name",
|
|
165
|
-
message: "Undefined name - Did you mean to use window.name instead?",
|
|
166
|
-
},
|
|
167
|
-
{
|
|
168
|
-
name: "status",
|
|
169
|
-
message:
|
|
170
|
-
"Undefined status - Did you mean to use window.status instead?",
|
|
171
|
-
},
|
|
172
|
-
{
|
|
173
|
-
name: "spyOn",
|
|
174
|
-
message: "Don't use spyOn directly, use jest.spyOn",
|
|
175
|
-
},
|
|
176
|
-
],
|
|
177
|
-
"no-restricted-properties": [
|
|
178
|
-
"error",
|
|
179
|
-
{
|
|
180
|
-
property: "bind",
|
|
181
|
-
message: "Don't o.f.bind(o, ...), use () => o.f(...)",
|
|
182
|
-
},
|
|
183
|
-
{
|
|
184
|
-
object: "ReactDOM",
|
|
185
|
-
property: "findDOMNode",
|
|
186
|
-
message: "Don't use ReactDOM.findDOMNode() as it is deprecated",
|
|
187
|
-
},
|
|
188
|
-
],
|
|
189
|
-
"no-restricted-syntax": [
|
|
190
|
-
"error",
|
|
191
|
-
{
|
|
192
|
-
selector: "AccessorProperty, TSAbstractAccessorProperty",
|
|
193
|
-
message:
|
|
194
|
-
"Accessor property syntax is not allowed, use getter and setters.",
|
|
195
|
-
},
|
|
196
|
-
{
|
|
197
|
-
selector: "PrivateIdentifier",
|
|
198
|
-
message:
|
|
199
|
-
"Private identifiers are not allowed, use TypeScript private fields.",
|
|
200
|
-
},
|
|
201
|
-
{
|
|
202
|
-
selector:
|
|
203
|
-
"JSXOpeningElement[name.name = /^[A-Z]/] > JSXAttribute[name.name = /-/]",
|
|
204
|
-
message:
|
|
205
|
-
"Passing hyphenated props to custom components is not type-safe. Prefer a camelCased equivalent if available. (See https://github.com/microsoft/TypeScript/issues/55182)",
|
|
206
|
-
},
|
|
207
|
-
{
|
|
208
|
-
selector:
|
|
209
|
-
"CallExpression[callee.object.name='window'][callee.property.name='open']",
|
|
210
|
-
message:
|
|
211
|
-
"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/",
|
|
212
|
-
},
|
|
213
|
-
],
|
|
214
|
-
"no-return-await": "error",
|
|
215
|
-
"no-throw-literal": "error",
|
|
216
|
-
"no-undef-init": "error",
|
|
217
|
-
"no-var": "error",
|
|
218
|
-
"object-shorthand": "error",
|
|
219
|
-
"prefer-const": [
|
|
220
|
-
"error",
|
|
221
|
-
{
|
|
222
|
-
destructuring: "all",
|
|
223
|
-
},
|
|
224
|
-
],
|
|
225
|
-
"prefer-object-spread": "error",
|
|
226
|
-
"prefer-rest-params": "error",
|
|
227
|
-
"prefer-spread": "error",
|
|
228
|
-
radix: "error",
|
|
229
|
-
},
|
|
230
|
-
},
|
|
231
|
-
{
|
|
232
|
-
files: ["**/*.tsx"],
|
|
233
|
-
rules: {
|
|
234
|
-
"react/no-deprecated": "error",
|
|
235
|
-
"react/forbid-elements": [
|
|
236
|
-
"error",
|
|
237
|
-
{
|
|
238
|
-
forbid: [
|
|
239
|
-
{
|
|
240
|
-
element: "video",
|
|
241
|
-
message:
|
|
242
|
-
"Don't use HTML video directly. Instead, use the App UI Kit <VideoCard /> as this respects users' auto-playing preferences",
|
|
243
|
-
},
|
|
244
|
-
{
|
|
245
|
-
element: "em",
|
|
246
|
-
message:
|
|
247
|
-
"Don't use <em> to italicize text. Canva's UI fonts don't support italic font style.",
|
|
248
|
-
},
|
|
249
|
-
{
|
|
250
|
-
element: "i",
|
|
251
|
-
message:
|
|
252
|
-
"Don't use <i> to italicize text. Canva's UI fonts don't support italic font style.",
|
|
253
|
-
},
|
|
254
|
-
{
|
|
255
|
-
element: "iframe",
|
|
256
|
-
message:
|
|
257
|
-
"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",
|
|
258
|
-
},
|
|
259
|
-
{
|
|
260
|
-
element: "script",
|
|
261
|
-
message:
|
|
262
|
-
"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",
|
|
263
|
-
},
|
|
264
|
-
{
|
|
265
|
-
element: "a",
|
|
266
|
-
message:
|
|
267
|
-
"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.",
|
|
268
|
-
},
|
|
269
|
-
{
|
|
270
|
-
element: "img",
|
|
271
|
-
message:
|
|
272
|
-
"Have you considered using <ImageCard /> from the App UI Kit instead?",
|
|
273
|
-
},
|
|
274
|
-
{
|
|
275
|
-
element: "embed",
|
|
276
|
-
message:
|
|
277
|
-
"Have you considered using <EmbedCard /> from the App UI Kit instead?",
|
|
278
|
-
},
|
|
279
|
-
{
|
|
280
|
-
element: "audio",
|
|
281
|
-
message:
|
|
282
|
-
"Have you considered using <AudioCard /> from the App UI Kit instead?",
|
|
283
|
-
},
|
|
284
|
-
{
|
|
285
|
-
element: "button",
|
|
286
|
-
message:
|
|
287
|
-
"Rather than using the native HTML <button> element, use the <Button> component from the App UI Kit for consistency and accessibility.",
|
|
288
|
-
},
|
|
289
|
-
{
|
|
290
|
-
element: "input",
|
|
291
|
-
message:
|
|
292
|
-
"Wherever possible, prefer using the form inputs from the App UI Kit for consistency and accessibility (TextInput, Checkbox, FileInput, etc).",
|
|
293
|
-
},
|
|
294
|
-
{
|
|
295
|
-
element: "base",
|
|
296
|
-
message:
|
|
297
|
-
"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",
|
|
298
|
-
},
|
|
299
|
-
{
|
|
300
|
-
element: "link",
|
|
301
|
-
message:
|
|
302
|
-
"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",
|
|
303
|
-
},
|
|
304
|
-
],
|
|
305
|
-
},
|
|
306
|
-
],
|
|
307
|
-
},
|
|
308
|
-
},
|
|
37
|
+
...general,
|
|
38
|
+
// This template is not yet translated, enable these rules when it is
|
|
39
|
+
// ...i18n,
|
|
309
40
|
];
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"name": "digital_asset_management",
|
|
4
4
|
"description": "An example app leveraging @canva/app-components to develop a digital asset management (DAM) app.",
|
|
5
5
|
"scripts": {
|
|
6
|
-
"extract": "formatjs extract
|
|
6
|
+
"extract": "formatjs extract \"src/**/*.{ts,tsx}\" --out-file dist/messages_en.json",
|
|
7
7
|
"build": "webpack --config webpack.config.cjs --mode production && npm run extract",
|
|
8
8
|
"format": "prettier '**/*.{css,ts,tsx}' --no-config --write",
|
|
9
9
|
"format:check": "prettier '**/*.{css,ts,tsx}' --no-config --check --ignore-path",
|
|
@@ -13,78 +13,86 @@
|
|
|
13
13
|
"lint:types": "tsc",
|
|
14
14
|
"start": "ts-node ./scripts/start/start.ts",
|
|
15
15
|
"test": "jest --no-cache",
|
|
16
|
-
"test:watch": "jest --watchAll"
|
|
16
|
+
"test:watch": "jest --watchAll",
|
|
17
|
+
"postinstall": "ts-node ./scripts/copy-env.ts"
|
|
17
18
|
},
|
|
18
19
|
"dependencies": {
|
|
19
|
-
"@canva/app-
|
|
20
|
-
"@canva/app-
|
|
21
|
-
"@canva/app-ui-kit": "^
|
|
22
|
-
"@canva/asset": "^1.
|
|
23
|
-
"@canva/design": "^
|
|
24
|
-
"@canva/
|
|
25
|
-
"@canva/
|
|
26
|
-
"
|
|
20
|
+
"@canva/app-components": "^1.0.0-beta.29",
|
|
21
|
+
"@canva/app-i18n-kit": "^1.0.2",
|
|
22
|
+
"@canva/app-ui-kit": "^4.4.0",
|
|
23
|
+
"@canva/asset": "^2.1.0",
|
|
24
|
+
"@canva/design": "^2.3.0",
|
|
25
|
+
"@canva/error": "^2.1.0",
|
|
26
|
+
"@canva/platform": "^2.1.0",
|
|
27
|
+
"@canva/user": "^2.1.0",
|
|
28
|
+
"cookie-parser": "1.4.7",
|
|
27
29
|
"cors": "2.8.5",
|
|
28
30
|
"react": "18.3.1",
|
|
29
31
|
"react-dom": "18.3.1",
|
|
30
|
-
"react-intl": "6.
|
|
32
|
+
"react-intl": "6.8.7"
|
|
31
33
|
},
|
|
32
34
|
"devDependencies": {
|
|
33
|
-
"@eslint/eslintrc": "3.
|
|
34
|
-
"@eslint/js": "9.
|
|
35
|
-
"@formatjs/cli": "6.
|
|
36
|
-
"@formatjs/ts-transformer": "3.13.
|
|
35
|
+
"@eslint/eslintrc": "3.2.0",
|
|
36
|
+
"@eslint/js": "9.16.0",
|
|
37
|
+
"@formatjs/cli": "6.3.14",
|
|
38
|
+
"@formatjs/ts-transformer": "3.13.26",
|
|
37
39
|
"@ngrok/ngrok": "1.4.1",
|
|
40
|
+
"@pmmmwh/react-refresh-webpack-plugin": "0.5.15",
|
|
38
41
|
"@svgr/webpack": "8.1.0",
|
|
42
|
+
"@testing-library/react": "16.1.0",
|
|
39
43
|
"@types/cors": "2.8.17",
|
|
40
44
|
"@types/debug": "4.1.12",
|
|
41
45
|
"@types/express": "4.17.21",
|
|
42
|
-
"@types/express-serve-static-core": "4.19.
|
|
43
|
-
"@types/jest": "29.5.
|
|
44
|
-
"@types/jsonwebtoken": "9.0.
|
|
46
|
+
"@types/express-serve-static-core": "4.19.6",
|
|
47
|
+
"@types/jest": "29.5.14",
|
|
48
|
+
"@types/jsonwebtoken": "9.0.7",
|
|
45
49
|
"@types/node": "20.10.0",
|
|
46
|
-
"@types/node-fetch": "2.6.
|
|
50
|
+
"@types/node-fetch": "2.6.12",
|
|
47
51
|
"@types/node-forge": "1.3.11",
|
|
48
52
|
"@types/nodemon": "1.19.6",
|
|
49
53
|
"@types/prompts": "2.4.9",
|
|
50
|
-
"@types/react": "18.3.
|
|
51
|
-
"@types/react-dom": "18.3.
|
|
54
|
+
"@types/react": "18.3.12",
|
|
55
|
+
"@types/react-dom": "18.3.1",
|
|
52
56
|
"@types/webpack-env": "1.18.5",
|
|
53
|
-
"@typescript-eslint/eslint-plugin": "8.
|
|
54
|
-
"@typescript-eslint/parser": "8.
|
|
57
|
+
"@typescript-eslint/eslint-plugin": "8.18.0",
|
|
58
|
+
"@typescript-eslint/parser": "8.18.0",
|
|
55
59
|
"chalk": "4.1.2",
|
|
56
60
|
"cli-table3": "0.6.5",
|
|
57
61
|
"css-loader": "7.1.2",
|
|
58
62
|
"css-modules-typescript-loader": "4.0.1",
|
|
59
|
-
"cssnano": "7.0.
|
|
60
|
-
"debug": "4.
|
|
61
|
-
"dotenv": "16.4.
|
|
62
|
-
"eslint": "9.
|
|
63
|
-
"eslint-plugin-
|
|
64
|
-
"eslint-plugin-
|
|
63
|
+
"cssnano": "7.0.6",
|
|
64
|
+
"debug": "4.4.0",
|
|
65
|
+
"dotenv": "16.4.7",
|
|
66
|
+
"eslint": "9.16.0",
|
|
67
|
+
"eslint-plugin-formatjs": "5.2.8",
|
|
68
|
+
"eslint-plugin-jest": "28.9.0",
|
|
69
|
+
"eslint-plugin-react": "7.37.2",
|
|
65
70
|
"exponential-backoff": "3.1.1",
|
|
66
|
-
"express": "4.
|
|
71
|
+
"express": "4.21.2",
|
|
67
72
|
"express-basic-auth": "1.2.1",
|
|
68
73
|
"jest": "29.7.0",
|
|
74
|
+
"jest-css-modules-transform": "4.4.2",
|
|
75
|
+
"jest-environment-jsdom": "29.7.0",
|
|
69
76
|
"jsonwebtoken": "9.0.2",
|
|
70
77
|
"jwks-rsa": "3.1.0",
|
|
71
|
-
"mini-css-extract-plugin": "2.9.
|
|
78
|
+
"mini-css-extract-plugin": "2.9.2",
|
|
72
79
|
"node-fetch": "3.3.2",
|
|
73
80
|
"node-forge": "1.3.1",
|
|
74
81
|
"nodemon": "3.0.1",
|
|
75
82
|
"postcss-loader": "8.1.1",
|
|
76
|
-
"prettier": "3.
|
|
83
|
+
"prettier": "3.4.2",
|
|
77
84
|
"prompts": "2.4.2",
|
|
85
|
+
"react-refresh": "0.16.0",
|
|
78
86
|
"style-loader": "4.0.0",
|
|
79
87
|
"terser-webpack-plugin": "5.3.10",
|
|
80
|
-
"ts-jest": "29.2.
|
|
88
|
+
"ts-jest": "29.2.5",
|
|
81
89
|
"ts-loader": "9.5.1",
|
|
82
90
|
"ts-node": "10.9.2",
|
|
83
91
|
"typescript": "5.5.4",
|
|
84
92
|
"url-loader": "4.1.1",
|
|
85
|
-
"webpack": "5.
|
|
93
|
+
"webpack": "5.97.1",
|
|
86
94
|
"webpack-cli": "5.1.4",
|
|
87
|
-
"webpack-dev-server": "5.0
|
|
95
|
+
"webpack-dev-server": "5.1.0",
|
|
88
96
|
"yargs": "17.7.2"
|
|
89
97
|
}
|
|
90
98
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import * as fs from "fs";
|
|
3
|
+
import * as path from "path";
|
|
4
|
+
|
|
5
|
+
const envPath = path.resolve(__dirname, "..", ".env");
|
|
6
|
+
const templatePath = path.resolve(__dirname, "..", ".env.template");
|
|
7
|
+
|
|
8
|
+
if (!fs.existsSync(envPath)) {
|
|
9
|
+
fs.copyFileSync(templatePath, envPath);
|
|
10
|
+
}
|
|
@@ -1,147 +1,14 @@
|
|
|
1
|
-
import { useEffect, useState } from "react";
|
|
2
1
|
import { SearchableListView } from "@canva/app-components";
|
|
3
|
-
import {
|
|
4
|
-
import type { Authentication } from "@canva/user";
|
|
5
|
-
import { auth } from "@canva/user";
|
|
2
|
+
import { Box } from "@canva/app-ui-kit";
|
|
6
3
|
import { findResources } from "./adapter";
|
|
7
4
|
import { config } from "./config";
|
|
8
5
|
import * as styles from "./index.css";
|
|
9
6
|
import "@canva/app-ui-kit/styles.css";
|
|
10
7
|
|
|
11
|
-
type AuthenticationState =
|
|
12
|
-
| "authenticated"
|
|
13
|
-
| "not_authenticated"
|
|
14
|
-
| "checking"
|
|
15
|
-
| "cancelled"
|
|
16
|
-
| "error";
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* This endpoint is defined in the ./backend/server.ts file. You need to
|
|
20
|
-
* register the endpoint in the Developer Portal before sending requests.
|
|
21
|
-
*
|
|
22
|
-
* BACKEND_HOST is configured in the root .env file, for more information,
|
|
23
|
-
* refer to the README.md.
|
|
24
|
-
*/
|
|
25
|
-
const AUTHENTICATION_CHECK_URL = `${BACKEND_HOST}/api/authentication/status`;
|
|
26
|
-
|
|
27
|
-
const checkAuthenticationStatus = async (
|
|
28
|
-
auth: Authentication,
|
|
29
|
-
): Promise<AuthenticationState> => {
|
|
30
|
-
/**
|
|
31
|
-
* Send a request to an endpoint that checks if the user is authenticated.
|
|
32
|
-
* This is example code, intended to convey the basic idea. When implementing this in your app, you might want more advanced checks.
|
|
33
|
-
*
|
|
34
|
-
* Note: You must register the provided endpoint via the Developer Portal.
|
|
35
|
-
*/
|
|
36
|
-
try {
|
|
37
|
-
const token = await auth.getCanvaUserToken();
|
|
38
|
-
const res = await fetch(AUTHENTICATION_CHECK_URL, {
|
|
39
|
-
headers: {
|
|
40
|
-
Authorization: `Bearer ${token}`,
|
|
41
|
-
},
|
|
42
|
-
method: "POST",
|
|
43
|
-
});
|
|
44
|
-
const body = await res.json();
|
|
45
|
-
|
|
46
|
-
if (body?.isAuthenticated) {
|
|
47
|
-
return "authenticated";
|
|
48
|
-
} else {
|
|
49
|
-
return "not_authenticated";
|
|
50
|
-
}
|
|
51
|
-
} catch (error) {
|
|
52
|
-
// eslint-disable-next-line no-console
|
|
53
|
-
console.error(error);
|
|
54
|
-
return "error";
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
|
|
58
8
|
export function App() {
|
|
59
|
-
|
|
60
|
-
const [authState, setAuthState] = useState<AuthenticationState>("checking");
|
|
61
|
-
|
|
62
|
-
useEffect(() => {
|
|
63
|
-
setAuthState("checking");
|
|
64
|
-
checkAuthenticationStatus(auth).then((status) => {
|
|
65
|
-
setAuthState(status);
|
|
66
|
-
});
|
|
67
|
-
}, []);
|
|
68
|
-
|
|
69
|
-
useEffect(() => {
|
|
70
|
-
if (authState === "not_authenticated") {
|
|
71
|
-
startAuthenticationFlow();
|
|
72
|
-
}
|
|
73
|
-
}, [authState]);
|
|
74
|
-
|
|
75
|
-
const startAuthenticationFlow = async () => {
|
|
76
|
-
try {
|
|
77
|
-
const response = await auth.requestAuthentication();
|
|
78
|
-
switch (response.status) {
|
|
79
|
-
case "COMPLETED":
|
|
80
|
-
setAuthState("authenticated");
|
|
81
|
-
break;
|
|
82
|
-
case "ABORTED":
|
|
83
|
-
// eslint-disable-next-line no-console
|
|
84
|
-
console.warn("Authentication aborted by user.");
|
|
85
|
-
setAuthState("cancelled");
|
|
86
|
-
break;
|
|
87
|
-
case "DENIED":
|
|
88
|
-
// eslint-disable-next-line no-console
|
|
89
|
-
console.warn("Authentication denied by user", response.details);
|
|
90
|
-
setAuthState("cancelled");
|
|
91
|
-
break;
|
|
92
|
-
default:
|
|
93
|
-
// eslint-disable-next-line no-console
|
|
94
|
-
console.log("Unknown auth state");
|
|
95
|
-
break;
|
|
96
|
-
}
|
|
97
|
-
} catch (e) {
|
|
98
|
-
// eslint-disable-next-line no-console
|
|
99
|
-
console.error(e);
|
|
100
|
-
setAuthState("error");
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
if (authState === "error") {
|
|
105
|
-
// eslint-disable-next-line no-console
|
|
106
|
-
console.warn(
|
|
107
|
-
"Warning: authentication not enabled on this app. Please enable auth with the instructions in README",
|
|
108
|
-
);
|
|
109
|
-
// Comment this next line out for production apps
|
|
110
|
-
setAuthState("authenticated");
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// If user has denied or aborted auth flow
|
|
114
|
-
if (authState === "cancelled") {
|
|
115
|
-
return (
|
|
116
|
-
<Box paddingEnd="2u" height="full" className={styles.centerInPage}>
|
|
117
|
-
<Rows spacing="2u" align="center">
|
|
118
|
-
<Alert tone="critical">
|
|
119
|
-
Something went wrong while authenticating
|
|
120
|
-
</Alert>
|
|
121
|
-
<Button
|
|
122
|
-
variant="primary"
|
|
123
|
-
onClick={startAuthenticationFlow}
|
|
124
|
-
stretch={true}
|
|
125
|
-
>
|
|
126
|
-
Start authentication flow
|
|
127
|
-
</Button>
|
|
128
|
-
</Rows>
|
|
129
|
-
</Box>
|
|
130
|
-
);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
return authState === "authenticated" ? (
|
|
9
|
+
return (
|
|
134
10
|
<Box className={styles.rootWrapper}>
|
|
135
11
|
<SearchableListView config={config} findResources={findResources} />
|
|
136
12
|
</Box>
|
|
137
|
-
) : (
|
|
138
|
-
<Box
|
|
139
|
-
width="full"
|
|
140
|
-
height="full"
|
|
141
|
-
paddingTop="1u"
|
|
142
|
-
className={styles.centerInPage}
|
|
143
|
-
>
|
|
144
|
-
<LoadingIndicator size="large" />
|
|
145
|
-
</Box>
|
|
146
13
|
);
|
|
147
14
|
}
|
|
@@ -4,6 +4,7 @@ const TerserPlugin = require("terser-webpack-plugin");
|
|
|
4
4
|
const { DefinePlugin, optimize } = require("webpack");
|
|
5
5
|
const chalk = require("chalk");
|
|
6
6
|
const { transform } = require("@formatjs/ts-transformer");
|
|
7
|
+
const ReactRefreshWebpackPlugin = require("@pmmmwh/react-refresh-webpack-plugin");
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
*
|
|
@@ -173,7 +174,8 @@ function buildConfig({
|
|
|
173
174
|
}),
|
|
174
175
|
// Apps can only submit a single JS file via the developer portal
|
|
175
176
|
new optimize.LimitChunkCountPlugin({ maxChunks: 1 }),
|
|
176
|
-
|
|
177
|
+
mode === "development" && new ReactRefreshWebpackPlugin(),
|
|
178
|
+
].filter(Boolean),
|
|
177
179
|
...buildDevConfig(devConfig),
|
|
178
180
|
};
|
|
179
181
|
}
|
|
@@ -20,7 +20,7 @@ In this template, we've included a basic obscenity filter to stop users from cre
|
|
|
20
20
|
|
|
21
21
|
### Backend
|
|
22
22
|
|
|
23
|
-
This template includes a simple Express server as a sample backend. Please note that this server is not production-ready, and we advise using it solely for instructional purposes to demonstrate API calls.
|
|
23
|
+
This template includes a simple Express server as a sample backend. Please note that this server is not production-ready, and we advise using it solely for instructional purposes to demonstrate API calls. If you require authentication for your app, we recommend looking at the authentication example provided in the [starter kit](https://github.com/canva-sdks/canva-apps-sdk-starter-kit).
|
|
24
24
|
|
|
25
25
|
### Thumbnails
|
|
26
26
|
|
|
@@ -93,7 +93,7 @@ export const createImageRouter = () => {
|
|
|
93
93
|
|
|
94
94
|
/**
|
|
95
95
|
* GET endpoint to retrieve user credits.
|
|
96
|
-
*
|
|
96
|
+
* Returns the current number of credits available to the user.
|
|
97
97
|
*/
|
|
98
98
|
router.get(Routes.CREDITS, async (req, res) => {
|
|
99
99
|
res.status(200).send({
|
|
@@ -103,7 +103,7 @@ export const createImageRouter = () => {
|
|
|
103
103
|
|
|
104
104
|
/**
|
|
105
105
|
* POST endpoint to purchase credits.
|
|
106
|
-
*
|
|
106
|
+
* Increments the user's credits by the number of credits in a bundle.
|
|
107
107
|
* This endpoint should be backed by proper input validation to prevent misuse.
|
|
108
108
|
*/
|
|
109
109
|
router.post(Routes.PURCHASE_CREDITS, async (req, res) => {
|
|
@@ -115,7 +115,7 @@ export const createImageRouter = () => {
|
|
|
115
115
|
|
|
116
116
|
/**
|
|
117
117
|
* GET endpoint to generate images based on a prompt.
|
|
118
|
-
*
|
|
118
|
+
* Generates images based on the provided prompt and adds a job to the processing queue.
|
|
119
119
|
* If there are not enough credits, it returns a 403 error.
|
|
120
120
|
* If the prompt parameter is missing, it returns a 400 error.
|
|
121
121
|
* Once the job is added to the queue, it returns a jobId that can be used to check the job status.
|
|
@@ -2,7 +2,6 @@ import * as express from "express";
|
|
|
2
2
|
import * as cors from "cors";
|
|
3
3
|
import { createBaseServer } from "../utils/backend/base_backend/create";
|
|
4
4
|
import { createImageRouter } from "./routers/image";
|
|
5
|
-
import { createAuthRouter } from "./routers/auth";
|
|
6
5
|
|
|
7
6
|
async function main() {
|
|
8
7
|
const router = express.Router();
|
|
@@ -37,12 +36,6 @@ async function main() {
|
|
|
37
36
|
*/
|
|
38
37
|
router.use(cors());
|
|
39
38
|
|
|
40
|
-
/**
|
|
41
|
-
* Add routes for authorisation.
|
|
42
|
-
*/
|
|
43
|
-
const authRouter = createAuthRouter();
|
|
44
|
-
router.use(authRouter);
|
|
45
|
-
|
|
46
39
|
/**
|
|
47
40
|
* Add routes for image generation.
|
|
48
41
|
*/
|