@canva/cli 1.11.0 → 1.13.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 +43 -0
- package/README.md +13 -0
- package/cli.js +593 -580
- package/lib/cjs/index.cjs +3 -3
- package/lib/esm/index.mjs +4 -4
- package/package.json +7 -2
- package/templates/base/package.json +7 -7
- package/templates/base/webpack.config.ts +0 -1
- package/templates/common/jest.config.mjs +1 -1
- package/templates/dam/backend/server.ts +8 -0
- package/templates/dam/canva-app.json +4 -0
- package/templates/dam/package.json +7 -7
- package/templates/dam/webpack.config.ts +0 -1
- package/templates/data_connector/README.md +1 -1
- package/templates/data_connector/package.json +7 -7
- package/templates/data_connector/webpack.config.ts +0 -1
- package/templates/gen_ai/backend/server.ts +17 -0
- package/templates/gen_ai/package.json +7 -7
- package/templates/gen_ai/src/api/api.ts +4 -0
- package/templates/gen_ai/webpack.config.ts +0 -1
- package/templates/hello_world/package.json +7 -7
- package/templates/hello_world/webpack.config.ts +0 -1
- package/templates/mls/README.md +81 -0
- package/templates/mls/canva-app.json +25 -0
- package/templates/mls/declarations/declarations.d.ts +29 -0
- package/templates/mls/eslint.config.mjs +14 -0
- package/templates/mls/jest.config.mjs +36 -0
- package/templates/mls/jest.setup.ts +37 -0
- package/templates/mls/package.json +117 -0
- package/templates/mls/scripts/copy_env.ts +13 -0
- package/templates/mls/scripts/ssl/ssl.ts +131 -0
- package/templates/mls/scripts/start/app_runner.ts +223 -0
- package/templates/mls/scripts/start/context.ts +171 -0
- package/templates/mls/scripts/start/start.ts +46 -0
- package/templates/mls/src/__tests__/app.tests.tsx +11 -0
- package/templates/mls/src/__tests__/office_selection_page.tests.tsx +72 -0
- package/templates/mls/src/__tests__/utils.tsx +19 -0
- package/templates/mls/src/adapter.ts +126 -0
- package/templates/mls/src/components/agent/agent_card.tsx +57 -0
- package/templates/mls/src/components/agent/agent_grid.tsx +37 -0
- package/templates/mls/src/components/agent/agent_list.tsx +17 -0
- package/templates/mls/src/components/agent/agent_search_filters.tsx +88 -0
- package/templates/mls/src/components/breadcrumb/breadcrumb.tsx +40 -0
- package/templates/mls/src/components/listing/listing_card.tsx +64 -0
- package/templates/mls/src/components/listing/listing_grid.tsx +37 -0
- package/templates/mls/src/components/listing/listing_list.tsx +21 -0
- package/templates/mls/src/components/listing/listing_search_filters.tsx +145 -0
- package/templates/mls/src/components/placeholders/placeholders.tsx +65 -0
- package/templates/mls/src/data.ts +359 -0
- package/templates/mls/src/index.tsx +4 -0
- package/templates/mls/src/intents/design_editor/app.tsx +44 -0
- package/templates/mls/src/intents/design_editor/index.tsx +25 -0
- package/templates/mls/src/pages/agent_details_page/agent_details_page.tsx +175 -0
- package/templates/mls/src/pages/list_page/agent_tab_panel.tsx +126 -0
- package/templates/mls/src/pages/list_page/list_page.tsx +67 -0
- package/templates/mls/src/pages/list_page/listing_tab_panel.tsx +135 -0
- package/templates/mls/src/pages/listing_details_page/listing_details_page.tsx +418 -0
- package/templates/mls/src/pages/loading_page/loading_page.tsx +152 -0
- package/templates/mls/src/pages/office_selection_page/office_selection_page.tsx +144 -0
- package/templates/mls/src/real_estate.type.ts +44 -0
- package/templates/mls/src/util/use_add_element.tsx +62 -0
- package/templates/mls/src/util/use_drag_element.tsx +68 -0
- package/templates/mls/styles/components.css +56 -0
- package/templates/mls/tsconfig.json +55 -0
- package/templates/mls/webpack.config.ts +253 -0
- package/templates/base/backend/routers/oauth.ts +0 -393
- package/templates/base/utils/backend/bearer_middleware/bearer_middleware.ts +0 -99
- package/templates/base/utils/backend/bearer_middleware/index.ts +0 -1
- package/templates/base/utils/backend/bearer_middleware/tests/bearer_middleware.tests.ts +0 -192
- package/templates/common/utils/backend/base_backend/create.ts +0 -104
- package/templates/gen_ai/backend/database/database.ts +0 -42
- package/templates/gen_ai/utils/backend/bearer_middleware/bearer_middleware.ts +0 -99
- package/templates/gen_ai/utils/backend/bearer_middleware/index.ts +0 -1
- /package/templates/base/{utils/backend → backend}/base_backend/create.ts +0 -0
- /package/templates/base/{utils/backend → backend}/jwt_middleware/index.ts +0 -0
- /package/templates/base/{utils/backend → backend}/jwt_middleware/jwt_middleware.ts +0 -0
- /package/templates/{common → gen_ai}/utils/backend/jwt_middleware/index.ts +0 -0
- /package/templates/{common → gen_ai}/utils/backend/jwt_middleware/jwt_middleware.ts +0 -0
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
import cors from "cors";
|
|
2
2
|
import express from "express";
|
|
3
3
|
import { createBaseServer } from "../utils/backend/base_backend/create";
|
|
4
|
+
import { createJwtMiddleware } from "../utils/backend/jwt_middleware/index";
|
|
4
5
|
import { createImageRouter } from "./routers/image";
|
|
5
6
|
|
|
6
7
|
async function main() {
|
|
8
|
+
// TODO: Set the CANVA_APP_ID environment variable in the project's .env file
|
|
9
|
+
const APP_ID = process.env.CANVA_APP_ID;
|
|
10
|
+
|
|
11
|
+
if (!APP_ID) {
|
|
12
|
+
throw new Error(
|
|
13
|
+
`The CANVA_APP_ID environment variable is undefined. Set the variable in the project's .env file.`,
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
|
|
7
17
|
const router = express.Router();
|
|
8
18
|
|
|
9
19
|
/**
|
|
@@ -36,6 +46,13 @@ async function main() {
|
|
|
36
46
|
*/
|
|
37
47
|
router.use(cors());
|
|
38
48
|
|
|
49
|
+
/**
|
|
50
|
+
* Initialize JWT middleware to verify Canva user tokens
|
|
51
|
+
* This middleware validates tokens sent from the frontend and extracts user information
|
|
52
|
+
*/
|
|
53
|
+
const jwtMiddleware = createJwtMiddleware(APP_ID);
|
|
54
|
+
router.use(jwtMiddleware);
|
|
55
|
+
|
|
39
56
|
/**
|
|
40
57
|
* Add routes for image generation.
|
|
41
58
|
*/
|
|
@@ -19,20 +19,20 @@
|
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@canva/app-hooks": "^0.0.0-beta.4",
|
|
22
|
-
"@canva/app-i18n-kit": "^1.
|
|
23
|
-
"@canva/app-ui-kit": "^5.
|
|
24
|
-
"@canva/asset": "^2.
|
|
25
|
-
"@canva/design": "^2.7.
|
|
22
|
+
"@canva/app-i18n-kit": "^1.2.0",
|
|
23
|
+
"@canva/app-ui-kit": "^5.4.0",
|
|
24
|
+
"@canva/asset": "^2.3.0",
|
|
25
|
+
"@canva/design": "^2.7.5",
|
|
26
26
|
"@canva/error": "^2.1.0",
|
|
27
27
|
"@canva/intents": "^2.0.0",
|
|
28
28
|
"@canva/platform": "^2.2.0",
|
|
29
|
-
"@canva/user": "^2.1.
|
|
29
|
+
"@canva/user": "^2.1.2",
|
|
30
30
|
"cookie-parser": "1.4.7",
|
|
31
31
|
"cors": "2.8.5",
|
|
32
32
|
"html-react-parser": "5.2.6",
|
|
33
33
|
"obscenity": "0.4.4",
|
|
34
|
-
"react": "^19.2.
|
|
35
|
-
"react-dom": "^19.2.
|
|
34
|
+
"react": "^19.2.3",
|
|
35
|
+
"react-dom": "^19.2.3",
|
|
36
36
|
"react-error-boundary": "6.0.0",
|
|
37
37
|
"react-intl": "^7.1.11",
|
|
38
38
|
"react-router-dom": "7.8.2"
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { auth } from "@canva/user";
|
|
1
2
|
import { POLLING_INTERVAL_IN_SECONDS } from "src/config";
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -167,8 +168,11 @@ export const purchaseCredits = async (): Promise<RemainingCreditsResult> => {
|
|
|
167
168
|
* @returns {Promise<Object>} - A promise that resolves to the response body.
|
|
168
169
|
*/
|
|
169
170
|
const sendRequest = async <T>(url: URL, options?: RequestInit): Promise<T> => {
|
|
171
|
+
const userToken = await auth.getCanvaUserToken();
|
|
172
|
+
|
|
170
173
|
const res = await fetch(url, {
|
|
171
174
|
headers: {
|
|
175
|
+
Authorization: `Bearer ${userToken}`,
|
|
172
176
|
...options?.headers,
|
|
173
177
|
},
|
|
174
178
|
...options,
|
|
@@ -20,16 +20,16 @@
|
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@canva/app-hooks": "^0.0.0-beta.4",
|
|
23
|
-
"@canva/app-i18n-kit": "^1.
|
|
24
|
-
"@canva/app-ui-kit": "^5.
|
|
25
|
-
"@canva/asset": "^2.
|
|
26
|
-
"@canva/design": "^2.7.
|
|
23
|
+
"@canva/app-i18n-kit": "^1.2.0",
|
|
24
|
+
"@canva/app-ui-kit": "^5.4.0",
|
|
25
|
+
"@canva/asset": "^2.3.0",
|
|
26
|
+
"@canva/design": "^2.7.5",
|
|
27
27
|
"@canva/error": "^2.1.0",
|
|
28
28
|
"@canva/intents": "^2.0.0",
|
|
29
29
|
"@canva/platform": "^2.2.0",
|
|
30
|
-
"@canva/user": "^2.1.
|
|
31
|
-
"react": "^19.2.
|
|
32
|
-
"react-dom": "^19.2.
|
|
30
|
+
"@canva/user": "^2.1.2",
|
|
31
|
+
"react": "^19.2.3",
|
|
32
|
+
"react-dom": "^19.2.3",
|
|
33
33
|
"react-intl": "^7.1.11"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# Real Estate MLS App
|
|
2
|
+
|
|
3
|
+
## Running this app
|
|
4
|
+
|
|
5
|
+
### Step 1: Start the local development server
|
|
6
|
+
|
|
7
|
+
To start the development server, run the following command:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install
|
|
11
|
+
npm start
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
The server becomes available at <http://localhost:8080>.
|
|
15
|
+
|
|
16
|
+
The app's source code is in the `src/app.tsx` file.
|
|
17
|
+
|
|
18
|
+
### Step 2: Preview the app
|
|
19
|
+
|
|
20
|
+
The local development server only exposes a JavaScript bundle, so you can't preview an app by visiting <http://localhost:8080>. You can only preview an app via the Canva editor.
|
|
21
|
+
|
|
22
|
+
To preview an app:
|
|
23
|
+
|
|
24
|
+
1. Create an app via the [Developer Portal](https://www.canva.com/developers/apps).
|
|
25
|
+
2. Select **App source > Development URL**.
|
|
26
|
+
3. In the **Development URL** field, enter the URL of the development server.
|
|
27
|
+
4. Click **Preview**. This opens the Canva editor (and the app) in a new tab.
|
|
28
|
+
5. Click **Open**. (This screen only appears when using an app for the first time.)
|
|
29
|
+
|
|
30
|
+
The app will appear in the side panel.
|
|
31
|
+
|
|
32
|
+
<details>
|
|
33
|
+
<summary>Previewing apps in Safari</summary>
|
|
34
|
+
|
|
35
|
+
By default, the development server is not HTTPS-enabled. This is convenient, as there's no need for a security certificate, but it prevents apps from being previewed in Safari.
|
|
36
|
+
|
|
37
|
+
**Why Safari requires the development server to be HTTPS-enabled?**
|
|
38
|
+
|
|
39
|
+
Canva itself is served via HTTPS and most browsers prevent HTTPS pages from loading scripts via non-HTTPS connections. Chrome and Firefox make exceptions for local servers, such as `localhost`, but Safari does not, so if you're using Safari, the development server must be HTTPS-enabled.
|
|
40
|
+
|
|
41
|
+
To learn more, see [Loading mixed-content resources](https://developer.mozilla.org/en-US/docs/Web/Security/Mixed_content#loading_mixed-content_resources).
|
|
42
|
+
|
|
43
|
+
To preview apps in Safari:
|
|
44
|
+
|
|
45
|
+
1. Start the development server with HTTPS enabled:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
npm start --use-https
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
2. Navigate to <https://localhost:8080>.
|
|
52
|
+
3. Bypass the invalid security certificate warning:
|
|
53
|
+
1. Click **Show details**.
|
|
54
|
+
2. Click **Visit website**.
|
|
55
|
+
4. In the Developer Portal, set the app's **Development URL** to <https://localhost:8080>.
|
|
56
|
+
5. Click preview (or refresh your app if it's already open).
|
|
57
|
+
|
|
58
|
+
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.
|
|
59
|
+
|
|
60
|
+
</details>
|
|
61
|
+
|
|
62
|
+
### Step 3 (Optional): Enable Hot Module Replacement
|
|
63
|
+
|
|
64
|
+
By default, every time you make a change to an app, you have to reload the entire app to see the results of those changes. If you enable [Hot Module Replacement](https://webpack.js.org/concepts/hot-module-replacement/) (HMR), changes will be reflected without a full reload, which significantly speeds up the development loop.
|
|
65
|
+
|
|
66
|
+
**Note:** HMR does **not** work while running the development server in a Docker container.
|
|
67
|
+
|
|
68
|
+
To enable HMR:
|
|
69
|
+
|
|
70
|
+
1. Navigate to an app via the [Your apps](https://www.canva.com/developers/apps).
|
|
71
|
+
1. Select **Security** -> **Credentials** -> **.env file**.
|
|
72
|
+
1. Copy the `.env` file contents.
|
|
73
|
+
1. Paste the contents into the starter kit's `.env` file. For example:
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
CANVA_APP_ORIGIN=https://app-aabbccddeeff.canva-apps.com
|
|
77
|
+
CANVA_HMR_ENABLED=true
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
1. Restart the local development server.
|
|
81
|
+
1. Reload the app manually to ensure that HMR takes effect.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://www.canva.dev/schemas/app/v1/manifest-schema.json",
|
|
3
|
+
"manifest_schema_version": 1,
|
|
4
|
+
"runtime": {
|
|
5
|
+
"permissions": [
|
|
6
|
+
{
|
|
7
|
+
"name": "canva:design:content:read",
|
|
8
|
+
"type": "mandatory"
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"name": "canva:design:content:write",
|
|
12
|
+
"type": "mandatory"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"name": "canva:asset:private:write",
|
|
16
|
+
"type": "mandatory"
|
|
17
|
+
}
|
|
18
|
+
]
|
|
19
|
+
},
|
|
20
|
+
"intent": {
|
|
21
|
+
"design_editor": {
|
|
22
|
+
"enrolled": true
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
declare module "*.css" {
|
|
2
|
+
const styles: { [className: string]: string };
|
|
3
|
+
export = styles;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
declare module "*.jpg" {
|
|
7
|
+
const content: string;
|
|
8
|
+
export default content;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
declare module "*.jpeg" {
|
|
12
|
+
const content: string;
|
|
13
|
+
export default content;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
declare module "*.png" {
|
|
17
|
+
const content: string;
|
|
18
|
+
export default content;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
declare module "*.svg" {
|
|
22
|
+
const content: React.FunctionComponent<{
|
|
23
|
+
size?: "tiny" | "small" | "medium" | "large";
|
|
24
|
+
className?: string;
|
|
25
|
+
}>;
|
|
26
|
+
export default content;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
declare const BACKEND_HOST: string;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { pathsToModuleNameMapper } from "ts-jest";
|
|
2
|
+
import tsconfig from "./tsconfig.json" with { type: "json" };
|
|
3
|
+
|
|
4
|
+
const { compilerOptions } = tsconfig;
|
|
5
|
+
|
|
6
|
+
/** @type {import('ts-jest').JestConfigWithTsJest} */
|
|
7
|
+
|
|
8
|
+
export default {
|
|
9
|
+
preset: "ts-jest",
|
|
10
|
+
testEnvironment: "jsdom",
|
|
11
|
+
testRegex: "(/(tests|__tests__)/.*\\.(tests))\\.tsx?$",
|
|
12
|
+
modulePathIgnorePatterns: ["./internal/", "./node_modules/"],
|
|
13
|
+
modulePaths: [compilerOptions.baseUrl],
|
|
14
|
+
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths),
|
|
15
|
+
transform: {
|
|
16
|
+
".+\\.(css)$": "jest-css-modules-transform",
|
|
17
|
+
"^.+\\.tsx?$": [
|
|
18
|
+
"ts-jest",
|
|
19
|
+
{
|
|
20
|
+
astTransformers: {
|
|
21
|
+
before: [
|
|
22
|
+
{
|
|
23
|
+
path: "@formatjs/ts-transformer/ts-jest-integration",
|
|
24
|
+
options: {
|
|
25
|
+
overrideIdFn: "[sha512:contenthash:base64:6]",
|
|
26
|
+
ast: true,
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
},
|
|
34
|
+
setupFiles: ["<rootDir>/jest.setup.ts"],
|
|
35
|
+
setupFilesAfterEnv: ["@testing-library/jest-dom"],
|
|
36
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// For usage information, see the README.md file.
|
|
2
|
+
|
|
3
|
+
// Import Canva SDK testing utilities
|
|
4
|
+
import * as asset from "@canva/asset/test";
|
|
5
|
+
import * as design from "@canva/design/test";
|
|
6
|
+
import * as error from "@canva/error/test";
|
|
7
|
+
import * as platform from "@canva/platform/test";
|
|
8
|
+
import * as user from "@canva/user/test";
|
|
9
|
+
import { TextEncoder } from "util";
|
|
10
|
+
|
|
11
|
+
// jsdom doesn't provide TextEncoder by default, so we polyfill it from Node's util module
|
|
12
|
+
global.TextEncoder = TextEncoder as unknown as typeof global.TextEncoder;
|
|
13
|
+
|
|
14
|
+
/*
|
|
15
|
+
Initialize test environments for each Canva SDK package
|
|
16
|
+
This sets up the necessary test infrastructure before mocking the actual SDK methods
|
|
17
|
+
*/
|
|
18
|
+
asset.initTestEnvironment();
|
|
19
|
+
design.initTestEnvironment();
|
|
20
|
+
error.initTestEnvironment();
|
|
21
|
+
platform.initTestEnvironment();
|
|
22
|
+
user.initTestEnvironment();
|
|
23
|
+
|
|
24
|
+
/*
|
|
25
|
+
Mock all Canva SDK packages except @canva/error
|
|
26
|
+
This allows tests to run without making real API calls to Canva's services
|
|
27
|
+
*/
|
|
28
|
+
jest.mock("@canva/asset");
|
|
29
|
+
jest.mock("@canva/design");
|
|
30
|
+
jest.mock("@canva/platform");
|
|
31
|
+
jest.mock("@canva/user");
|
|
32
|
+
|
|
33
|
+
/*
|
|
34
|
+
Important: @canva/error should not be mocked
|
|
35
|
+
Use it to simulate API error responses from other mocks by throwing CanvaError instances
|
|
36
|
+
This allows testing of error handling scenarios
|
|
37
|
+
*/
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
{
|
|
2
|
+
"private": true,
|
|
3
|
+
"name": "real_estate_mls",
|
|
4
|
+
"description": "A Real Estate MLS reference app built with the Canva Apps SDK.",
|
|
5
|
+
"license": "SEE LICENSE IN LICENSE.md",
|
|
6
|
+
"author": "Canva Pty Ltd.",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"extract": "formatjs extract \"src/**/*.{ts,tsx}\" --out-file dist/messages_en.json",
|
|
9
|
+
"build": "webpack --config webpack.config.ts --mode production && npm run extract",
|
|
10
|
+
"format": "prettier '**/*.{css,ts,tsx}' --no-config --write",
|
|
11
|
+
"format:check": "prettier '**/*.{css,ts,tsx}' --no-config --check --ignore-path",
|
|
12
|
+
"format:file": "prettier $1 --no-config --write",
|
|
13
|
+
"lint": "eslint .",
|
|
14
|
+
"lint:fix": "eslint . --fix",
|
|
15
|
+
"lint:types": "tsc",
|
|
16
|
+
"start": "ts-node ./scripts/start/start.ts",
|
|
17
|
+
"start:preview": "npm run start -- --preview",
|
|
18
|
+
"test": "jest --no-cache",
|
|
19
|
+
"test:watch": "jest --watchAll",
|
|
20
|
+
"test:update": "npm run test -- -u",
|
|
21
|
+
"postinstall": "ts-node ./scripts/copy_env.ts"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@canva/app-hooks": "^0.0.0-beta.4",
|
|
25
|
+
"@canva/app-i18n-kit": "^1.2.0",
|
|
26
|
+
"@canva/app-ui-kit": "^5.4.0",
|
|
27
|
+
"@canva/asset": "^2.3.0",
|
|
28
|
+
"@canva/design": "^2.7.5",
|
|
29
|
+
"@canva/error": "^2.1.0",
|
|
30
|
+
"@canva/intents": "^2.0.0",
|
|
31
|
+
"@canva/platform": "^2.2.0",
|
|
32
|
+
"@canva/user": "^2.1.2",
|
|
33
|
+
"@tanstack/react-query": "5.87.1",
|
|
34
|
+
"@types/react-infinite-scroller": "1.2.5",
|
|
35
|
+
"clsx": "2.1.1",
|
|
36
|
+
"loglevel": "1.9.2",
|
|
37
|
+
"react": "^19.2.3",
|
|
38
|
+
"react-dom": "^19.2.3",
|
|
39
|
+
"react-hook-form": "7.66.0",
|
|
40
|
+
"react-infinite-scroller": "1.2.6",
|
|
41
|
+
"react-intl": "^7.1.11",
|
|
42
|
+
"react-router-dom": "7.8.2"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@canva/app-eslint-plugin": "^1.0.0-beta.7",
|
|
46
|
+
"@canva/cli": ">= 0.0.1-beta.13",
|
|
47
|
+
"@formatjs/cli": "6.7.2",
|
|
48
|
+
"@formatjs/ts-transformer": "3.14.0",
|
|
49
|
+
"@ngrok/ngrok": "1.5.2",
|
|
50
|
+
"@pmmmwh/react-refresh-webpack-plugin": "0.6.1",
|
|
51
|
+
"@svgr/webpack": "8.1.0",
|
|
52
|
+
"@testing-library/jest-dom": "6.8.0",
|
|
53
|
+
"@testing-library/react": "16.3.0",
|
|
54
|
+
"@testing-library/user-event": "14.6.1",
|
|
55
|
+
"@types/express": "4.17.21",
|
|
56
|
+
"@types/express-serve-static-core": "5.0.7",
|
|
57
|
+
"@types/jest": "29.5.14",
|
|
58
|
+
"@types/jsonwebtoken": "9.0.10",
|
|
59
|
+
"@types/node": "20.19.2",
|
|
60
|
+
"@types/node-fetch": "2.6.13",
|
|
61
|
+
"@types/node-forge": "1.3.14",
|
|
62
|
+
"@types/nodemon": "1.19.6",
|
|
63
|
+
"@types/react": "19.2.2",
|
|
64
|
+
"@types/react-dom": "19.2.1",
|
|
65
|
+
"@types/webpack-env": "1.18.8",
|
|
66
|
+
"chalk": "4.1.2",
|
|
67
|
+
"cli-table3": "0.6.5",
|
|
68
|
+
"css-loader": "7.1.2",
|
|
69
|
+
"css-modules-typescript-loader": "4.0.1",
|
|
70
|
+
"cssnano": "7.1.1",
|
|
71
|
+
"debug": "4.4.1",
|
|
72
|
+
"dotenv": "16.6.0",
|
|
73
|
+
"express": "4.22.1",
|
|
74
|
+
"express-basic-auth": "1.2.1",
|
|
75
|
+
"jest": "29.7.0",
|
|
76
|
+
"jest-css-modules-transform": "4.4.2",
|
|
77
|
+
"jest-environment-jsdom": "29.7.0",
|
|
78
|
+
"jsonwebtoken": "9.0.2",
|
|
79
|
+
"jwks-rsa": "3.2.0",
|
|
80
|
+
"mini-css-extract-plugin": "2.9.4",
|
|
81
|
+
"node-fetch": "3.3.2",
|
|
82
|
+
"node-forge": "1.3.2",
|
|
83
|
+
"nodemon": "3.0.1",
|
|
84
|
+
"open": "8.4.2",
|
|
85
|
+
"postcss-loader": "8.1.1",
|
|
86
|
+
"prettier": "3.6.2",
|
|
87
|
+
"react-refresh": "0.17.0",
|
|
88
|
+
"style-loader": "4.0.0",
|
|
89
|
+
"terser-webpack-plugin": "5.3.14",
|
|
90
|
+
"tree-kill": "1.2.2",
|
|
91
|
+
"ts-jest": "29.4.1",
|
|
92
|
+
"ts-loader": "9.5.4",
|
|
93
|
+
"ts-node": "10.9.2",
|
|
94
|
+
"typescript": "5.9.2",
|
|
95
|
+
"url-loader": "4.1.1",
|
|
96
|
+
"webpack": "5.99.9",
|
|
97
|
+
"webpack-cli": "6.0.1",
|
|
98
|
+
"webpack-dev-server": "5.2.2",
|
|
99
|
+
"yargs": "17.7.2"
|
|
100
|
+
},
|
|
101
|
+
"overrides": {
|
|
102
|
+
"react-infinite-scroller": {
|
|
103
|
+
"react": "$react"
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
"keywords": [
|
|
107
|
+
"canva-apps-sdk"
|
|
108
|
+
],
|
|
109
|
+
"engines": {
|
|
110
|
+
"node": "^18 || ^20.10.0",
|
|
111
|
+
"npm": "^9 || ^10"
|
|
112
|
+
},
|
|
113
|
+
"canvaCliMetadata": {
|
|
114
|
+
"name": "@canva/cli",
|
|
115
|
+
"version": "1.1.0"
|
|
116
|
+
}
|
|
117
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/* eslint-disable no-console */
|
|
3
|
+
import fs from "fs";
|
|
4
|
+
import path from "path";
|
|
5
|
+
|
|
6
|
+
const envPath = path.resolve(__dirname, "..", ".env");
|
|
7
|
+
const templatePath = path.resolve(__dirname, "..", ".env.template");
|
|
8
|
+
|
|
9
|
+
if (!fs.existsSync(templatePath)) {
|
|
10
|
+
console.warn(".env.template file does not exist, skipping copy of .env file");
|
|
11
|
+
} else if (!fs.existsSync(envPath)) {
|
|
12
|
+
fs.copyFileSync(templatePath, envPath);
|
|
13
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import crypto from "crypto";
|
|
2
|
+
import fs from "fs/promises";
|
|
3
|
+
import { pki } from "node-forge";
|
|
4
|
+
import path from "path";
|
|
5
|
+
|
|
6
|
+
const SSL_CERT_DIR = path.resolve(process.cwd(), "..", "..", ".ssl");
|
|
7
|
+
const CERT_FILE = path.resolve(SSL_CERT_DIR, "certificate.pem");
|
|
8
|
+
const KEY_FILE = path.resolve(SSL_CERT_DIR, "private-key.pem");
|
|
9
|
+
|
|
10
|
+
export interface Certificate {
|
|
11
|
+
keyFile: string;
|
|
12
|
+
certFile: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const CERT_ATTRS: { name: string; value: string }[] = [
|
|
16
|
+
{
|
|
17
|
+
name: "commonName",
|
|
18
|
+
value: "localhost",
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
name: "countryName",
|
|
22
|
+
value: "AU",
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
name: "stateOrProvinceName",
|
|
26
|
+
value: "New South Wales",
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
name: "localityName",
|
|
30
|
+
value: "Sydney",
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
name: "organizationName",
|
|
34
|
+
value: "Test",
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
name: "organizationalUnitName",
|
|
38
|
+
value: "Test",
|
|
39
|
+
},
|
|
40
|
+
];
|
|
41
|
+
|
|
42
|
+
const generateRsaKeys = async (): Promise<{
|
|
43
|
+
publicKey: string;
|
|
44
|
+
privateKey: string;
|
|
45
|
+
}> =>
|
|
46
|
+
new Promise((resolve, reject) => {
|
|
47
|
+
crypto.generateKeyPair(
|
|
48
|
+
"rsa",
|
|
49
|
+
{
|
|
50
|
+
modulusLength: 2096,
|
|
51
|
+
publicKeyEncoding: {
|
|
52
|
+
type: "spki",
|
|
53
|
+
format: "pem",
|
|
54
|
+
},
|
|
55
|
+
privateKeyEncoding: {
|
|
56
|
+
type: "pkcs8",
|
|
57
|
+
format: "pem",
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
(err, publicKey, privateKey) => {
|
|
61
|
+
if (err) {
|
|
62
|
+
reject(err);
|
|
63
|
+
} else {
|
|
64
|
+
resolve({ publicKey, privateKey });
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
const generateCertificate = (opts: {
|
|
71
|
+
privateKey: string;
|
|
72
|
+
publicKey: string;
|
|
73
|
+
}): string => {
|
|
74
|
+
const privateKey = pki.privateKeyFromPem(opts.privateKey);
|
|
75
|
+
const publicKey = pki.publicKeyFromPem(opts.publicKey);
|
|
76
|
+
|
|
77
|
+
const cert = pki.createCertificate();
|
|
78
|
+
|
|
79
|
+
cert.publicKey = publicKey;
|
|
80
|
+
cert.serialNumber = "01";
|
|
81
|
+
cert.validity.notBefore = new Date();
|
|
82
|
+
cert.validity.notAfter = new Date();
|
|
83
|
+
cert.validity.notAfter.setFullYear(cert.validity.notBefore.getFullYear() + 1);
|
|
84
|
+
|
|
85
|
+
cert.setSubject(CERT_ATTRS);
|
|
86
|
+
cert.setIssuer(CERT_ATTRS);
|
|
87
|
+
|
|
88
|
+
// the actual certificate signing
|
|
89
|
+
cert.sign(privateKey);
|
|
90
|
+
|
|
91
|
+
// now convert the Forge certificate to PEM format
|
|
92
|
+
return pki.certificateToPem(cert);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const writeCertFiles = async (opts: {
|
|
96
|
+
cert: string;
|
|
97
|
+
privateKey: string;
|
|
98
|
+
}): Promise<void> => {
|
|
99
|
+
const { cert, privateKey } = opts;
|
|
100
|
+
|
|
101
|
+
await fs.mkdir(SSL_CERT_DIR, { recursive: true });
|
|
102
|
+
await Promise.all([
|
|
103
|
+
fs.writeFile(CERT_FILE, cert, { encoding: "utf8" }),
|
|
104
|
+
fs.writeFile(KEY_FILE, privateKey, { encoding: "utf8" }),
|
|
105
|
+
]);
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const cerfFilesExist = async (): Promise<boolean> => {
|
|
109
|
+
try {
|
|
110
|
+
await Promise.all([
|
|
111
|
+
fs.access(CERT_FILE, fs.constants.R_OK | fs.constants.W_OK),
|
|
112
|
+
fs.access(KEY_FILE, fs.constants.R_OK | fs.constants.W_OK),
|
|
113
|
+
]);
|
|
114
|
+
return true;
|
|
115
|
+
} catch {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
export const createOrRetrieveCertificate = async (): Promise<Certificate> => {
|
|
121
|
+
if (!(await cerfFilesExist())) {
|
|
122
|
+
const keys = await generateRsaKeys();
|
|
123
|
+
const cert = generateCertificate(keys);
|
|
124
|
+
await writeCertFiles({ cert, privateKey: keys.privateKey });
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return {
|
|
128
|
+
certFile: CERT_FILE,
|
|
129
|
+
keyFile: KEY_FILE,
|
|
130
|
+
};
|
|
131
|
+
};
|