@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.
Files changed (78) hide show
  1. package/CHANGELOG.md +43 -0
  2. package/README.md +13 -0
  3. package/cli.js +593 -580
  4. package/lib/cjs/index.cjs +3 -3
  5. package/lib/esm/index.mjs +4 -4
  6. package/package.json +7 -2
  7. package/templates/base/package.json +7 -7
  8. package/templates/base/webpack.config.ts +0 -1
  9. package/templates/common/jest.config.mjs +1 -1
  10. package/templates/dam/backend/server.ts +8 -0
  11. package/templates/dam/canva-app.json +4 -0
  12. package/templates/dam/package.json +7 -7
  13. package/templates/dam/webpack.config.ts +0 -1
  14. package/templates/data_connector/README.md +1 -1
  15. package/templates/data_connector/package.json +7 -7
  16. package/templates/data_connector/webpack.config.ts +0 -1
  17. package/templates/gen_ai/backend/server.ts +17 -0
  18. package/templates/gen_ai/package.json +7 -7
  19. package/templates/gen_ai/src/api/api.ts +4 -0
  20. package/templates/gen_ai/webpack.config.ts +0 -1
  21. package/templates/hello_world/package.json +7 -7
  22. package/templates/hello_world/webpack.config.ts +0 -1
  23. package/templates/mls/README.md +81 -0
  24. package/templates/mls/canva-app.json +25 -0
  25. package/templates/mls/declarations/declarations.d.ts +29 -0
  26. package/templates/mls/eslint.config.mjs +14 -0
  27. package/templates/mls/jest.config.mjs +36 -0
  28. package/templates/mls/jest.setup.ts +37 -0
  29. package/templates/mls/package.json +117 -0
  30. package/templates/mls/scripts/copy_env.ts +13 -0
  31. package/templates/mls/scripts/ssl/ssl.ts +131 -0
  32. package/templates/mls/scripts/start/app_runner.ts +223 -0
  33. package/templates/mls/scripts/start/context.ts +171 -0
  34. package/templates/mls/scripts/start/start.ts +46 -0
  35. package/templates/mls/src/__tests__/app.tests.tsx +11 -0
  36. package/templates/mls/src/__tests__/office_selection_page.tests.tsx +72 -0
  37. package/templates/mls/src/__tests__/utils.tsx +19 -0
  38. package/templates/mls/src/adapter.ts +126 -0
  39. package/templates/mls/src/components/agent/agent_card.tsx +57 -0
  40. package/templates/mls/src/components/agent/agent_grid.tsx +37 -0
  41. package/templates/mls/src/components/agent/agent_list.tsx +17 -0
  42. package/templates/mls/src/components/agent/agent_search_filters.tsx +88 -0
  43. package/templates/mls/src/components/breadcrumb/breadcrumb.tsx +40 -0
  44. package/templates/mls/src/components/listing/listing_card.tsx +64 -0
  45. package/templates/mls/src/components/listing/listing_grid.tsx +37 -0
  46. package/templates/mls/src/components/listing/listing_list.tsx +21 -0
  47. package/templates/mls/src/components/listing/listing_search_filters.tsx +145 -0
  48. package/templates/mls/src/components/placeholders/placeholders.tsx +65 -0
  49. package/templates/mls/src/data.ts +359 -0
  50. package/templates/mls/src/index.tsx +4 -0
  51. package/templates/mls/src/intents/design_editor/app.tsx +44 -0
  52. package/templates/mls/src/intents/design_editor/index.tsx +25 -0
  53. package/templates/mls/src/pages/agent_details_page/agent_details_page.tsx +175 -0
  54. package/templates/mls/src/pages/list_page/agent_tab_panel.tsx +126 -0
  55. package/templates/mls/src/pages/list_page/list_page.tsx +67 -0
  56. package/templates/mls/src/pages/list_page/listing_tab_panel.tsx +135 -0
  57. package/templates/mls/src/pages/listing_details_page/listing_details_page.tsx +418 -0
  58. package/templates/mls/src/pages/loading_page/loading_page.tsx +152 -0
  59. package/templates/mls/src/pages/office_selection_page/office_selection_page.tsx +144 -0
  60. package/templates/mls/src/real_estate.type.ts +44 -0
  61. package/templates/mls/src/util/use_add_element.tsx +62 -0
  62. package/templates/mls/src/util/use_drag_element.tsx +68 -0
  63. package/templates/mls/styles/components.css +56 -0
  64. package/templates/mls/tsconfig.json +55 -0
  65. package/templates/mls/webpack.config.ts +253 -0
  66. package/templates/base/backend/routers/oauth.ts +0 -393
  67. package/templates/base/utils/backend/bearer_middleware/bearer_middleware.ts +0 -99
  68. package/templates/base/utils/backend/bearer_middleware/index.ts +0 -1
  69. package/templates/base/utils/backend/bearer_middleware/tests/bearer_middleware.tests.ts +0 -192
  70. package/templates/common/utils/backend/base_backend/create.ts +0 -104
  71. package/templates/gen_ai/backend/database/database.ts +0 -42
  72. package/templates/gen_ai/utils/backend/bearer_middleware/bearer_middleware.ts +0 -99
  73. package/templates/gen_ai/utils/backend/bearer_middleware/index.ts +0 -1
  74. /package/templates/base/{utils/backend → backend}/base_backend/create.ts +0 -0
  75. /package/templates/base/{utils/backend → backend}/jwt_middleware/index.ts +0 -0
  76. /package/templates/base/{utils/backend → backend}/jwt_middleware/jwt_middleware.ts +0 -0
  77. /package/templates/{common → gen_ai}/utils/backend/jwt_middleware/index.ts +0 -0
  78. /package/templates/{common → gen_ai}/utils/backend/jwt_middleware/jwt_middleware.ts +0 -0
@@ -1,104 +0,0 @@
1
- /* eslint-disable no-console */
2
- import debug from "debug";
3
- import express from "express";
4
- import type { NextFunction, Request, Response } from "express";
5
- import fs from "fs";
6
- import http from "http";
7
- import https from "https";
8
-
9
- const serverDebug = debug("server");
10
-
11
- interface BaseServer {
12
- app: express.Express;
13
-
14
- /**
15
- * Starts the server on the address or port provided
16
- * @param address port number or string address or if left undefined express defaults to port 3000
17
- */
18
- start: (address: number | string | undefined) => void;
19
- }
20
-
21
- /**
22
- * createBaseServer instantiates a customised express server with:
23
- * - json body handling
24
- * - health check endpoint
25
- * - catchall endpoint
26
- * - error handler catch route
27
- * - process termination handling
28
- * - debug logging - prefix starting your server with `DEBUG=server npm run XXX`
29
- *
30
- * @returns BaseServer object containing the express app and a start function
31
- */
32
- export function createBaseServer(router: express.Router): BaseServer {
33
- const SHOULD_ENABLE_HTTPS = process.env?.SHOULD_ENABLE_HTTPS === "true";
34
- const HTTPS_CERT_FILE = process.env?.HTTPS_CERT_FILE;
35
- const HTTPS_KEY_FILE = process.env?.HTTPS_KEY_FILE;
36
-
37
- const app = express();
38
- app.use(express.json());
39
-
40
- // It can help to provide an extra layer of obsecurity to reduce server fingerprinting.
41
- app.disable("x-powered-by");
42
-
43
- // Health check endpoint
44
- app.get("/healthz", (req, res) => {
45
- res.sendStatus(200);
46
- });
47
-
48
- // logging middleware
49
- app.use((req, _res, next) => {
50
- serverDebug(`${new Date().toISOString()}: ${req.method} ${req.url}`);
51
- next();
52
- });
53
-
54
- // Custom routes router
55
- app.use(router);
56
-
57
- // catch all router
58
- app.all("*", (req, res) => {
59
- res.status(404).send({
60
- error: `unhandled '${req.method}' on '${req.url}'`,
61
- });
62
- });
63
-
64
- // default error handler
65
- app.use((err: Error, _req: Request, res: Response, _next: NextFunction) => {
66
- console.error(err.stack);
67
- res.status(500).send({
68
- error: "something went wrong",
69
- });
70
- });
71
-
72
- let server;
73
- if (SHOULD_ENABLE_HTTPS) {
74
- if (!HTTPS_CERT_FILE || !HTTPS_KEY_FILE) {
75
- throw new Error(
76
- "Looks like you're running the example with --use-https flag, but SSL certificates haven't been generated. Please remove the .ssl/ folder and re-run the command again.",
77
- );
78
- }
79
-
80
- server = https.createServer(
81
- {
82
- key: fs.readFileSync(HTTPS_KEY_FILE),
83
- cert: fs.readFileSync(HTTPS_CERT_FILE),
84
- },
85
- app,
86
- );
87
- } else {
88
- server = http.createServer(app);
89
- }
90
-
91
- return {
92
- app,
93
- start: (address: number | string | undefined) => {
94
- console.log(`Listening on '${address}'`);
95
- server.listen(address);
96
- process.on("SIGTERM", () => {
97
- serverDebug("SIGTERM signal received: closing HTTP server");
98
- server.close(() => {
99
- serverDebug("HTTP server closed");
100
- });
101
- });
102
- },
103
- };
104
- }
@@ -1,42 +0,0 @@
1
- import fs from "fs/promises";
2
- import path from "path";
3
-
4
- /**
5
- * This file creates a "database" out of a JSON file. It's only for
6
- * demonstration purposes. A real app should use a real database.
7
- */
8
- const DATABASE_FILE_PATH = path.join(__dirname, "db.json");
9
-
10
- interface Database<T> {
11
- read(): Promise<T>;
12
- write(data: T): Promise<void>;
13
- }
14
-
15
- export class JSONFileDatabase<T> implements Database<T> {
16
- constructor(private readonly seedData: T) {}
17
-
18
- // Creates a database file if one doesn't already exist
19
- private async init(): Promise<void> {
20
- try {
21
- // Do nothing, since the database is initialized
22
- await fs.stat(DATABASE_FILE_PATH);
23
- } catch {
24
- const file = JSON.stringify(this.seedData);
25
- await fs.writeFile(DATABASE_FILE_PATH, file);
26
- }
27
- }
28
-
29
- // Loads and parses the database file
30
- async read(): Promise<T> {
31
- await this.init();
32
- const file = await fs.readFile(DATABASE_FILE_PATH, "utf8");
33
- return JSON.parse(file);
34
- }
35
-
36
- // Overwrites the database file with provided data
37
- async write(data: T): Promise<void> {
38
- await this.init();
39
- const file = JSON.stringify(data);
40
- await fs.writeFile(DATABASE_FILE_PATH, file);
41
- }
42
- }
@@ -1,99 +0,0 @@
1
- /* eslint-disable no-console */
2
- import debug from "debug";
3
- import type { NextFunction, Request, Response } from "express";
4
-
5
- /**
6
- * Prefix your start command with `DEBUG=express:middleware:bearer` to enable debug logging
7
- * for this middleware
8
- */
9
- const debugLogger = debug("express:middleware:bearer");
10
-
11
- /**
12
- * Augment the Express request context to include the appId/userId/brandId fields decoded
13
- * from the JWT.
14
- */
15
- declare module "express-serve-static-core" {
16
- export interface Request {
17
- user_id: string;
18
- }
19
- }
20
-
21
- const sendUnauthorizedResponse = (res: Response, message?: string) =>
22
- res.status(401).json({ error: "unauthorized", message });
23
-
24
- /**
25
- * An Express.js middleware verifying a Bearer token.
26
- * This middleware extracts the token from the `Authorization` header.
27
- *
28
- * @param getTokenFromRequest - A function that extracts a token from the request. If a token isn't found, throw a `JWTAuthorizationError`.
29
- * @returns An Express.js middleware for verifying and decoding JWTs.
30
- */
31
- export function createBearerMiddleware(
32
- tokenToUser: (access_token: string) => Promise<string | undefined>,
33
- getTokenFromRequest: GetTokenFromRequest = getTokenFromHttpHeader,
34
- ): (req: Request, res: Response, next: NextFunction) => void {
35
- return async (req, res, next) => {
36
- try {
37
- debugLogger(`processing token for '${req.url}'`);
38
-
39
- const token = await getTokenFromRequest(req);
40
- const user = await tokenToUser(token);
41
-
42
- if (!user) {
43
- throw new AuthorizationError("Token is invalid");
44
- }
45
-
46
- req["user_id"] = user;
47
-
48
- return next();
49
- } catch (e) {
50
- if (e instanceof AuthorizationError) {
51
- return sendUnauthorizedResponse(res, e.message);
52
- }
53
-
54
- return next(e);
55
- }
56
- };
57
- }
58
-
59
- export type GetTokenFromRequest = (req: Request) => Promise<string> | string;
60
-
61
- export const getTokenFromHttpHeader: GetTokenFromRequest = (
62
- req: Request,
63
- ): string => {
64
- // The names of a HTTP header bearing the JWT, and a scheme
65
- const headerName = "Authorization";
66
- const schemeName = "Bearer";
67
-
68
- const header = req.header(headerName);
69
- if (!header) {
70
- throw new AuthorizationError(`Missing the "${headerName}" header`);
71
- }
72
-
73
- if (!header.match(new RegExp(`^${schemeName}\\s+[^\\s]+$`, "i"))) {
74
- console.trace(
75
- `jwtMiddleware: failed to match token in "${headerName}" header`,
76
- );
77
- throw new AuthorizationError(
78
- `Missing a "${schemeName}" token in the "${headerName}" header`,
79
- );
80
- }
81
-
82
- const token = header.replace(new RegExp(`^${schemeName}\\s+`, "i"), "");
83
-
84
- return token;
85
- };
86
-
87
- /**
88
- * A class representing JWT validation errors in the JWT middleware.
89
- * The error message provided to the constructor will be forwarded to the
90
- * API consumer trying to access a JWT-protected endpoint.
91
- * @private
92
- */
93
- export class AuthorizationError extends Error {
94
- constructor(message: string) {
95
- super(message);
96
-
97
- Object.setPrototypeOf(this, AuthorizationError.prototype);
98
- }
99
- }
@@ -1 +0,0 @@
1
- export { createBearerMiddleware } from "./bearer_middleware";