@canva/cli 0.0.1-beta.2 → 0.0.1-beta.4
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 +177 -109
- package/cli.js +267 -267
- package/package.json +1 -1
- package/templates/base/backend/routers/oauth.ts +393 -0
- package/templates/base/eslint.config.mjs +0 -2
- package/templates/base/package.json +22 -19
- 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/common/.gitignore.template +5 -6
- package/templates/common/README.md +4 -74
- package/templates/common/conf/eslint-general.mjs +26 -0
- package/templates/common/conf/eslint-i18n.mjs +18 -3
- package/templates/dam/backend/server.ts +0 -7
- package/templates/dam/package.json +27 -27
- package/templates/dam/src/app.tsx +2 -135
- 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 +0 -2
- package/templates/gen_ai/package.json +28 -28
- package/templates/gen_ai/src/api/api.ts +1 -39
- 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 +8 -6
- package/templates/gen_ai/src/components/index.ts +0 -1
- 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/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/hello_world/eslint.config.mjs +0 -2
- package/templates/hello_world/package.json +20 -19
- package/templates/hello_world/src/app.tsx +4 -2
- package/templates/hello_world/utils/use_add_element.ts +48 -0
- package/templates/hello_world/utils/use_feature_support.ts +28 -0
- 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/utils/backend/jwt_middleware/index.ts +0 -1
- package/templates/gen_ai/utils/backend/jwt_middleware/jwt_middleware.ts +0 -229
- package/templates/gen_ai/utils/backend/jwt_middleware/tests/jwt_middleware.tests.ts +0 -630
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-require-imports */
|
|
2
|
+
import type { NextFunction, Request, Response } from "express";
|
|
3
|
+
import type {
|
|
4
|
+
createBearerMiddleware,
|
|
5
|
+
GetTokenFromRequest,
|
|
6
|
+
} from "../bearer_middleware";
|
|
7
|
+
|
|
8
|
+
type Middleware = (req: Request, res: Response, next: NextFunction) => void;
|
|
9
|
+
|
|
10
|
+
describe("createBearerMiddleware", () => {
|
|
11
|
+
let fakeGetTokenFromRequest: jest.MockedFn<GetTokenFromRequest>;
|
|
12
|
+
let verify: jest.MockedFn<(token: string) => Promise<string | undefined>>;
|
|
13
|
+
|
|
14
|
+
let req: Request;
|
|
15
|
+
let res: Response;
|
|
16
|
+
let next: jest.MockedFn<() => void>;
|
|
17
|
+
|
|
18
|
+
let AuthorizationError: typeof Error;
|
|
19
|
+
let createBearerMiddlewareFn: typeof createBearerMiddleware;
|
|
20
|
+
let bearerMiddleware: Middleware;
|
|
21
|
+
|
|
22
|
+
beforeEach(() => {
|
|
23
|
+
jest.resetAllMocks();
|
|
24
|
+
jest.resetModules();
|
|
25
|
+
|
|
26
|
+
fakeGetTokenFromRequest = jest.fn();
|
|
27
|
+
verify = jest.fn();
|
|
28
|
+
|
|
29
|
+
const middlewareModule = require("../bearer_middleware");
|
|
30
|
+
createBearerMiddlewareFn = middlewareModule.createBearerMiddleware;
|
|
31
|
+
AuthorizationError = middlewareModule.AuthorizationError;
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
describe("When called", () => {
|
|
35
|
+
beforeEach(() => {
|
|
36
|
+
req = {
|
|
37
|
+
header: (_name: string) => undefined,
|
|
38
|
+
} as Request;
|
|
39
|
+
|
|
40
|
+
res = {
|
|
41
|
+
status: jest.fn().mockReturnThis(),
|
|
42
|
+
json: jest.fn().mockReturnThis(),
|
|
43
|
+
send: jest.fn().mockReturnThis(),
|
|
44
|
+
} as unknown as Response;
|
|
45
|
+
|
|
46
|
+
next = jest.fn();
|
|
47
|
+
|
|
48
|
+
bearerMiddleware = createBearerMiddlewareFn(
|
|
49
|
+
verify,
|
|
50
|
+
fakeGetTokenFromRequest,
|
|
51
|
+
);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
describe("When `getTokenFromRequest` throws an exception ('Fake error')", () => {
|
|
55
|
+
beforeEach(() => {
|
|
56
|
+
fakeGetTokenFromRequest.mockRejectedValue(
|
|
57
|
+
new AuthorizationError("Fake error"),
|
|
58
|
+
);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it(`Does not call next() and returns HTTP 401 with error = "unauthorized" and message = "Fake error"`, async () => {
|
|
62
|
+
expect.assertions(8);
|
|
63
|
+
|
|
64
|
+
expect(fakeGetTokenFromRequest).not.toHaveBeenCalled();
|
|
65
|
+
await bearerMiddleware(req, res, next);
|
|
66
|
+
|
|
67
|
+
expect(fakeGetTokenFromRequest).toHaveBeenCalledTimes(1);
|
|
68
|
+
expect(fakeGetTokenFromRequest).toHaveBeenLastCalledWith(req);
|
|
69
|
+
|
|
70
|
+
expect(res.status).toHaveBeenCalledTimes(1);
|
|
71
|
+
expect(res.status).toHaveBeenLastCalledWith(401);
|
|
72
|
+
|
|
73
|
+
expect(res.json).toHaveBeenCalledTimes(1);
|
|
74
|
+
expect(res.json).toHaveBeenLastCalledWith({
|
|
75
|
+
error: "unauthorized",
|
|
76
|
+
message: "Fake error",
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
expect(next).not.toHaveBeenCalled();
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
describe("When the middleware cannot verify the token", () => {
|
|
84
|
+
beforeEach(() => {
|
|
85
|
+
fakeGetTokenFromRequest.mockReturnValue("TOKEN");
|
|
86
|
+
|
|
87
|
+
verify.mockImplementation(() => Promise.resolve(undefined));
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it(`Does not call next() and returns HTTP 401 with error = "unauthorized" and message = "Token is invalid"`, async () => {
|
|
91
|
+
expect.assertions(5);
|
|
92
|
+
|
|
93
|
+
await bearerMiddleware(req, res, next);
|
|
94
|
+
|
|
95
|
+
expect(res.status).toHaveBeenCalledTimes(1);
|
|
96
|
+
expect(res.status).toHaveBeenLastCalledWith(401);
|
|
97
|
+
|
|
98
|
+
expect(res.json).toHaveBeenCalledTimes(1);
|
|
99
|
+
expect(res.json).toHaveBeenLastCalledWith({
|
|
100
|
+
error: "unauthorized",
|
|
101
|
+
message: "Token is invalid",
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
expect(next).not.toHaveBeenCalled();
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
describe("getTokenFromHttpHeader", () => {
|
|
111
|
+
let getHeader: jest.MockedFn<(name: string) => string | undefined>;
|
|
112
|
+
let req: Request;
|
|
113
|
+
let getTokenFromHttpHeader: (req: Request) => string;
|
|
114
|
+
let AuthorizationError: typeof Error;
|
|
115
|
+
|
|
116
|
+
beforeEach(() => {
|
|
117
|
+
getHeader = jest.fn();
|
|
118
|
+
req = {
|
|
119
|
+
header: (name: string) => getHeader(name),
|
|
120
|
+
} as Request;
|
|
121
|
+
|
|
122
|
+
const bearerMiddlewareModule = require("../bearer_middleware");
|
|
123
|
+
getTokenFromHttpHeader = bearerMiddlewareModule.getTokenFromHttpHeader;
|
|
124
|
+
AuthorizationError = bearerMiddlewareModule.AuthorizationError;
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
describe("When the 'Authorization' header is missing", () => {
|
|
128
|
+
beforeEach(() => {
|
|
129
|
+
getHeader.mockReturnValue(undefined);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it(`Throws a AuthorizationError with message = 'Missing the "Authorization" header'`, async () => {
|
|
133
|
+
expect.assertions(3);
|
|
134
|
+
|
|
135
|
+
expect(() => getTokenFromHttpHeader(req)).toThrow(
|
|
136
|
+
new AuthorizationError('Missing the "Authorization" header'),
|
|
137
|
+
);
|
|
138
|
+
expect(getHeader).toHaveBeenCalledTimes(1);
|
|
139
|
+
expect(getHeader).toHaveBeenLastCalledWith("Authorization");
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
describe("When the 'Authorization' header doesn't have a Bearer scheme", () => {
|
|
144
|
+
beforeEach(() => {
|
|
145
|
+
getHeader.mockReturnValue("Beerer FAKE_TOKEN");
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it(`Throws a AuthorizationError with message = 'Missing a "Bearer" token in the "Authorization" header''`, async () => {
|
|
149
|
+
expect.assertions(3);
|
|
150
|
+
|
|
151
|
+
expect(() => getTokenFromHttpHeader(req)).toThrow(
|
|
152
|
+
new AuthorizationError(
|
|
153
|
+
'Missing a "Bearer" token in the "Authorization" header',
|
|
154
|
+
),
|
|
155
|
+
);
|
|
156
|
+
expect(getHeader).toHaveBeenCalledTimes(1);
|
|
157
|
+
expect(getHeader).toHaveBeenLastCalledWith("Authorization");
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
describe("When the 'Authorization' Bearer scheme header doesn't have a token", () => {
|
|
162
|
+
beforeEach(() => {
|
|
163
|
+
getHeader.mockReturnValue("Bearer ");
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it(`Throws a AuthorizationError with message = 'Missing a "Bearer" token in the "Authorization" header'`, async () => {
|
|
167
|
+
expect.assertions(3);
|
|
168
|
+
|
|
169
|
+
expect(() => getTokenFromHttpHeader(req)).toThrow(
|
|
170
|
+
new AuthorizationError(
|
|
171
|
+
'Missing a "Bearer" token in the "Authorization" header',
|
|
172
|
+
),
|
|
173
|
+
);
|
|
174
|
+
expect(getHeader).toHaveBeenCalledTimes(1);
|
|
175
|
+
expect(getHeader).toHaveBeenLastCalledWith("Authorization");
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
describe("When the 'Authorization' Bearer scheme header has a token", () => {
|
|
180
|
+
beforeEach(() => {
|
|
181
|
+
getHeader.mockReturnValue("Bearer TOKEN");
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it(`Returns the token`, async () => {
|
|
185
|
+
expect.assertions(3);
|
|
186
|
+
|
|
187
|
+
expect(getTokenFromHttpHeader(req)).toEqual("TOKEN");
|
|
188
|
+
expect(getHeader).toHaveBeenCalledTimes(1);
|
|
189
|
+
expect(getHeader).toHaveBeenLastCalledWith("Authorization");
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
EmbedElement,
|
|
3
|
+
ImageElement,
|
|
4
|
+
RichtextElement,
|
|
5
|
+
TableElement,
|
|
6
|
+
TextElement,
|
|
7
|
+
VideoElement,
|
|
8
|
+
} from "@canva/design";
|
|
9
|
+
import { addElementAtCursor, addElementAtPoint } from "@canva/design";
|
|
10
|
+
import { useFeatureSupport } from "./use_feature_support";
|
|
11
|
+
import { features } from "@canva/platform";
|
|
12
|
+
import { useEffect, useState } from "react";
|
|
13
|
+
|
|
14
|
+
type AddElementParams =
|
|
15
|
+
| ImageElement
|
|
16
|
+
| VideoElement
|
|
17
|
+
| EmbedElement
|
|
18
|
+
| TextElement
|
|
19
|
+
| RichtextElement
|
|
20
|
+
| TableElement;
|
|
21
|
+
|
|
22
|
+
export const useAddElement = () => {
|
|
23
|
+
const isSupported = useFeatureSupport();
|
|
24
|
+
|
|
25
|
+
// Store a wrapped addElement function that checks feature support
|
|
26
|
+
const [addElement, setAddElement] = useState(() => {
|
|
27
|
+
return (element: AddElementParams) => {
|
|
28
|
+
if (features.isSupported(addElementAtPoint)) {
|
|
29
|
+
return addElementAtPoint(element);
|
|
30
|
+
} else if (features.isSupported(addElementAtCursor)) {
|
|
31
|
+
return addElementAtCursor(element);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
const addElement = (element: AddElementParams) => {
|
|
38
|
+
if (isSupported(addElementAtPoint)) {
|
|
39
|
+
return addElementAtPoint(element);
|
|
40
|
+
} else if (isSupported(addElementAtCursor)) {
|
|
41
|
+
return addElementAtCursor(element);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
setAddElement(() => addElement);
|
|
45
|
+
}, [isSupported]);
|
|
46
|
+
|
|
47
|
+
return addElement;
|
|
48
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { features } from "@canva/platform";
|
|
2
|
+
import type { Feature } from "@canva/platform";
|
|
3
|
+
import { useState, useEffect } from "react";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* This hook allows re-rendering of a React component whenever
|
|
7
|
+
* the state of feature support changes in Canva.
|
|
8
|
+
*
|
|
9
|
+
* @returns isSupported - callback to inspect a Canva SDK method.
|
|
10
|
+
**/
|
|
11
|
+
export function useFeatureSupport() {
|
|
12
|
+
// Store a wrapped function that checks feature support
|
|
13
|
+
const [isSupported, setIsSupported] = useState(() => {
|
|
14
|
+
return (...args: Feature[]) => features.isSupported(...args);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
// create new function ref when feature support changes to trigger
|
|
19
|
+
// re-render
|
|
20
|
+
return features.registerOnSupportChange(() => {
|
|
21
|
+
setIsSupported(() => {
|
|
22
|
+
return (...args: Feature[]) => features.isSupported(...args);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
}, []);
|
|
26
|
+
|
|
27
|
+
return isSupported;
|
|
28
|
+
}
|
|
@@ -63,18 +63,15 @@ To preview apps in Safari:
|
|
|
63
63
|
1. Start the development server with HTTPS enabled:
|
|
64
64
|
|
|
65
65
|
```bash
|
|
66
|
-
# Run the main app
|
|
67
66
|
npm start --use-https
|
|
68
|
-
|
|
69
|
-
# Run an example
|
|
70
|
-
npm start <example-name> --use-https
|
|
71
67
|
```
|
|
72
68
|
|
|
73
69
|
2. Navigate to <https://localhost:8080>.
|
|
74
70
|
3. Bypass the invalid security certificate warning:
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
71
|
+
1. Click **Show details**.
|
|
72
|
+
2. Click **Visit website**.
|
|
73
|
+
4. In the Developer Portal, set the app's **Development URL** to <https://localhost:8080>.
|
|
74
|
+
5. Click preview (or refresh your app if it's already open).
|
|
78
75
|
|
|
79
76
|
You need to bypass the invalid security certificate warning every time you start the local server. A similar warning will appear in other browsers (and will need to be bypassed) whenever HTTPS is enabled.
|
|
80
77
|
|
|
@@ -181,70 +178,3 @@ To use ngrok, you'll need to do the following:
|
|
|
181
178
|
```
|
|
182
179
|
|
|
183
180
|
This environment variable is available for the current terminal session, so the command must be re-run for each new session. Alternatively, you can add the variable to your terminal's default parameters.
|
|
184
|
-
|
|
185
|
-
## Run the development server with ngrok and add authentication to the app
|
|
186
|
-
|
|
187
|
-
These steps demonstrate how to start the local development server with ngrok.
|
|
188
|
-
|
|
189
|
-
From your app's root directory
|
|
190
|
-
|
|
191
|
-
1. Stop any running scripts, and run the following command to launch the backend and frontend development servers. The `--ngrok` parameter exposes the backend server via a publicly accessible URL.
|
|
192
|
-
|
|
193
|
-
```bash
|
|
194
|
-
npm start --ngrok
|
|
195
|
-
```
|
|
196
|
-
|
|
197
|
-
2. After ngrok is running, copy your ngrok url
|
|
198
|
-
(e.g. `https://0000-0000.ngrok-free.app`) to the clipboard.
|
|
199
|
-
|
|
200
|
-
1. Go to your app in the [Developer Portal](https://www.canva.com/developers/apps).
|
|
201
|
-
2. Navigate to the "Add authentication" section of your app.
|
|
202
|
-
3. Check "This app requires authentication"
|
|
203
|
-
4. In the "Redirect URL" text box, enter your ngrok url followed by `/redirect-url` e.g.
|
|
204
|
-
`https://0000-0000.ngrok-free.app/redirect-url`
|
|
205
|
-
5. In the "Authentication base URL" text box, enter your ngrok url followed by `/` e.g.
|
|
206
|
-
`https://0000-0000.ngrok-free.app/`
|
|
207
|
-
Note: Your ngrok URL changes each time you restart ngrok. Keep these fields up to
|
|
208
|
-
date to ensure your example authentication step will run.
|
|
209
|
-
|
|
210
|
-
3. Make sure the app is authenticating users by making the following changes:
|
|
211
|
-
|
|
212
|
-
1. Replace
|
|
213
|
-
|
|
214
|
-
`router.post("/resources/find", async (req, res) => {`
|
|
215
|
-
|
|
216
|
-
with
|
|
217
|
-
|
|
218
|
-
`router.post("/api/resources/find", async (req, res) => {`
|
|
219
|
-
|
|
220
|
-
in [./backend/routers/auth.ts](./backend/routers/auth.ts). Adding `/api/` to the route ensures
|
|
221
|
-
the JWT middleware authenticates requests.
|
|
222
|
-
|
|
223
|
-
2. Replace
|
|
224
|
-
|
|
225
|
-
``const url = new URL(`${BACKEND_HOST}/resources/find`);``
|
|
226
|
-
|
|
227
|
-
with
|
|
228
|
-
|
|
229
|
-
``const url = new URL(`${BACKEND_HOST}/api/resources/find`);``
|
|
230
|
-
|
|
231
|
-
in [./adapter.ts](./adapter.ts)
|
|
232
|
-
|
|
233
|
-
3. Comment out these lines in [./app.tsx](./app.tsx)
|
|
234
|
-
|
|
235
|
-
```typescript
|
|
236
|
-
// Comment this next line out for production apps
|
|
237
|
-
setAuthState("authenticated");
|
|
238
|
-
```
|
|
239
|
-
|
|
240
|
-
4. Navigate to your app at `https://www.canva.com/developers/apps`, and click **Preview** to preview the app.
|
|
241
|
-
1. A new screen will appear asking if you want to authenticate.
|
|
242
|
-
Press **Connect** to start the authentication flow.
|
|
243
|
-
2. A ngrok screen may appear. If it does, select **Visit Site**
|
|
244
|
-
3. An authentication popup will appear. For the username, enter `username`, and
|
|
245
|
-
for the password enter `password`.
|
|
246
|
-
4. If successful, you will be redirected back to your app.
|
|
247
|
-
5. You can now modify the `/redirect-url` function in `server.ts` to authenticate with your third-party
|
|
248
|
-
asset manager, and `/api/resources/find` to pull assets from your third-party asset manager.
|
|
249
|
-
|
|
250
|
-
See `https://www.canva.dev/docs/apps/authenticating-users/` for more details.
|
|
@@ -179,6 +179,32 @@ export default [
|
|
|
179
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
180
|
},
|
|
181
181
|
],
|
|
182
|
+
"no-restricted-imports": [
|
|
183
|
+
"warn",
|
|
184
|
+
{
|
|
185
|
+
// Warn when importing static assets that increase bundle size
|
|
186
|
+
patterns: [
|
|
187
|
+
// Images
|
|
188
|
+
{
|
|
189
|
+
group: ["*.png", "*.jpg", "*.jpeg", "*.gif"],
|
|
190
|
+
message:
|
|
191
|
+
"Inline images increase app bundle size and degrade app performance. Wherever possible, please use a CDN or external hosting service to dynamically load assets.",
|
|
192
|
+
},
|
|
193
|
+
// Videos
|
|
194
|
+
{
|
|
195
|
+
group: ["*.mp4", "*.webm", "*.ogg"],
|
|
196
|
+
message:
|
|
197
|
+
"Inline videos increase app bundle size and degrade app performance. Wherever possible, please use a CDN or external hosting service to dynamically load assets.",
|
|
198
|
+
},
|
|
199
|
+
// Audio
|
|
200
|
+
{
|
|
201
|
+
group: ["*.mp3", "*.wav", "*.ogg"],
|
|
202
|
+
message:
|
|
203
|
+
"Inline audio files increase app bundle size and degrade app performance. Wherever possible, please use a CDN or external hosting service to dynamically load assets.",
|
|
204
|
+
},
|
|
205
|
+
],
|
|
206
|
+
},
|
|
207
|
+
],
|
|
182
208
|
"no-return-await": "error",
|
|
183
209
|
"no-throw-literal": "error",
|
|
184
210
|
"no-undef-init": "error",
|
|
@@ -7,7 +7,22 @@ export default [
|
|
|
7
7
|
},
|
|
8
8
|
rules: {
|
|
9
9
|
"formatjs/no-invalid-icu": "error",
|
|
10
|
-
"formatjs/no-literal-string-in-jsx":
|
|
10
|
+
"formatjs/no-literal-string-in-jsx": [
|
|
11
|
+
2,
|
|
12
|
+
{
|
|
13
|
+
props: {
|
|
14
|
+
// These rules are for @canva/app-ui-kit components.
|
|
15
|
+
// For your own components, suppress any false positives using eslint ignore comments.
|
|
16
|
+
include: [
|
|
17
|
+
["*", "(*Label|label|alt)"],
|
|
18
|
+
["*", "(title|description|name|text)"],
|
|
19
|
+
["*", "(placeholder|additionalPlaceholder|defaultValue)"],
|
|
20
|
+
["FormField", "error"],
|
|
21
|
+
],
|
|
22
|
+
exclude: [["FormattedMessage", "description"]],
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
],
|
|
11
26
|
"formatjs/enforce-description": "error",
|
|
12
27
|
"formatjs/enforce-default-message": "error",
|
|
13
28
|
"formatjs/enforce-placeholders": "error",
|
|
@@ -18,6 +33,6 @@ export default [
|
|
|
18
33
|
"formatjs/no-offset": "error",
|
|
19
34
|
"formatjs/blocklist-elements": [2, ["selectordinal"]],
|
|
20
35
|
"formatjs/no-complex-selectors": "error",
|
|
21
|
-
}
|
|
22
|
-
}
|
|
36
|
+
},
|
|
37
|
+
},
|
|
23
38
|
];
|
|
@@ -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 { createDamRouter } from "./routers/dam";
|
|
5
|
-
import { createAuthRouter } from "./routers/auth";
|
|
6
5
|
|
|
7
6
|
async function main() {
|
|
8
7
|
// TODO: Set the CANVA_APP_ID environment variable in the project's .env file
|
|
@@ -46,12 +45,6 @@ async function main() {
|
|
|
46
45
|
*/
|
|
47
46
|
router.use(cors());
|
|
48
47
|
|
|
49
|
-
/**
|
|
50
|
-
* Add routes for authorisation.
|
|
51
|
-
*/
|
|
52
|
-
const authRouter = createAuthRouter();
|
|
53
|
-
router.use(authRouter);
|
|
54
|
-
|
|
55
48
|
/**
|
|
56
49
|
* Add routes for digital asset management.
|
|
57
50
|
*/
|
|
@@ -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",
|
|
@@ -16,14 +16,14 @@
|
|
|
16
16
|
"test:watch": "jest --watchAll"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@canva/app-
|
|
20
|
-
"@canva/app-
|
|
21
|
-
"@canva/app-ui-kit": "^
|
|
22
|
-
"@canva/asset": "^
|
|
23
|
-
"@canva/design": "^1.
|
|
24
|
-
"@canva/platform": "^
|
|
25
|
-
"@canva/user": "^
|
|
26
|
-
"cookie-parser": "1.4.
|
|
19
|
+
"@canva/app-components": "^1.0.0-beta.29",
|
|
20
|
+
"@canva/app-i18n-kit": "^1.0.0",
|
|
21
|
+
"@canva/app-ui-kit": "^4.1.0",
|
|
22
|
+
"@canva/asset": "^2.0.0",
|
|
23
|
+
"@canva/design": "^2.1.0",
|
|
24
|
+
"@canva/platform": "^2.0.0",
|
|
25
|
+
"@canva/user": "^2.0.0",
|
|
26
|
+
"cookie-parser": "1.4.7",
|
|
27
27
|
"cors": "2.8.5",
|
|
28
28
|
"react": "18.3.1",
|
|
29
29
|
"react-dom": "18.3.1",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@eslint/eslintrc": "3.1.0",
|
|
34
|
-
"@eslint/js": "9.
|
|
34
|
+
"@eslint/js": "9.12.0",
|
|
35
35
|
"@formatjs/cli": "6.2.12",
|
|
36
36
|
"@formatjs/ts-transformer": "3.13.14",
|
|
37
37
|
"@ngrok/ngrok": "1.4.1",
|
|
@@ -39,32 +39,32 @@
|
|
|
39
39
|
"@types/cors": "2.8.17",
|
|
40
40
|
"@types/debug": "4.1.12",
|
|
41
41
|
"@types/express": "4.17.21",
|
|
42
|
-
"@types/express-serve-static-core": "4.19.
|
|
43
|
-
"@types/jest": "29.5.
|
|
44
|
-
"@types/jsonwebtoken": "9.0.
|
|
42
|
+
"@types/express-serve-static-core": "4.19.6",
|
|
43
|
+
"@types/jest": "29.5.13",
|
|
44
|
+
"@types/jsonwebtoken": "9.0.7",
|
|
45
45
|
"@types/node": "20.10.0",
|
|
46
46
|
"@types/node-fetch": "2.6.11",
|
|
47
47
|
"@types/node-forge": "1.3.11",
|
|
48
48
|
"@types/nodemon": "1.19.6",
|
|
49
49
|
"@types/prompts": "2.4.9",
|
|
50
|
-
"@types/react": "18.3.
|
|
51
|
-
"@types/react-dom": "18.3.
|
|
50
|
+
"@types/react": "18.3.11",
|
|
51
|
+
"@types/react-dom": "18.3.1",
|
|
52
52
|
"@types/webpack-env": "1.18.5",
|
|
53
|
-
"@typescript-eslint/eslint-plugin": "8.
|
|
54
|
-
"@typescript-eslint/parser": "8.
|
|
53
|
+
"@typescript-eslint/eslint-plugin": "8.9.0",
|
|
54
|
+
"@typescript-eslint/parser": "8.9.0",
|
|
55
55
|
"chalk": "4.1.2",
|
|
56
56
|
"cli-table3": "0.6.5",
|
|
57
57
|
"css-loader": "7.1.2",
|
|
58
58
|
"css-modules-typescript-loader": "4.0.1",
|
|
59
|
-
"cssnano": "7.0.
|
|
60
|
-
"debug": "4.3.
|
|
59
|
+
"cssnano": "7.0.6",
|
|
60
|
+
"debug": "4.3.7",
|
|
61
61
|
"dotenv": "16.4.5",
|
|
62
|
-
"eslint": "
|
|
63
|
-
"eslint-plugin-formatjs": "
|
|
64
|
-
"eslint-plugin-jest": "28.8.
|
|
65
|
-
"eslint-plugin-react": "7.
|
|
62
|
+
"eslint": "9.12.0",
|
|
63
|
+
"eslint-plugin-formatjs": "5.0.0",
|
|
64
|
+
"eslint-plugin-jest": "28.8.3",
|
|
65
|
+
"eslint-plugin-react": "7.37.1",
|
|
66
66
|
"exponential-backoff": "3.1.1",
|
|
67
|
-
"express": "4.
|
|
67
|
+
"express": "4.21.1",
|
|
68
68
|
"express-basic-auth": "1.2.1",
|
|
69
69
|
"jest": "29.7.0",
|
|
70
70
|
"jsonwebtoken": "9.0.2",
|
|
@@ -78,14 +78,14 @@
|
|
|
78
78
|
"prompts": "2.4.2",
|
|
79
79
|
"style-loader": "4.0.0",
|
|
80
80
|
"terser-webpack-plugin": "5.3.10",
|
|
81
|
-
"ts-jest": "29.2.
|
|
81
|
+
"ts-jest": "29.2.5",
|
|
82
82
|
"ts-loader": "9.5.1",
|
|
83
83
|
"ts-node": "10.9.2",
|
|
84
84
|
"typescript": "5.5.4",
|
|
85
85
|
"url-loader": "4.1.1",
|
|
86
|
-
"webpack": "5.
|
|
86
|
+
"webpack": "5.95.0",
|
|
87
87
|
"webpack-cli": "5.1.4",
|
|
88
|
-
"webpack-dev-server": "5.0
|
|
88
|
+
"webpack-dev-server": "5.1.0",
|
|
89
89
|
"yargs": "17.7.2"
|
|
90
90
|
}
|
|
91
91
|
}
|