@canva/cli 1.10.0 → 1.12.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 (126) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/README.md +2 -0
  3. package/cli.js +596 -574
  4. package/lib/cjs/index.cjs +2 -2
  5. package/lib/esm/index.mjs +2 -2
  6. package/lib/index.d.ts +2 -0
  7. package/package.json +7 -2
  8. package/templates/base/package.json +9 -8
  9. package/templates/base/styles/components.css +18 -0
  10. package/templates/common/.env.template +1 -1
  11. package/templates/common/jest.config.mjs +1 -1
  12. package/templates/dam/backend/server.ts +8 -0
  13. package/templates/dam/canva-app.json +9 -0
  14. package/templates/dam/package.json +10 -8
  15. package/templates/dam/src/index.tsx +3 -21
  16. package/templates/dam/src/intents/design_editor/index.tsx +25 -0
  17. package/templates/data_connector/README.md +1 -1
  18. package/templates/data_connector/package.json +9 -8
  19. package/templates/data_connector/src/api/data_sources/designs.tsx +1 -1
  20. package/templates/data_connector/src/api/data_sources/templates.tsx +1 -1
  21. package/templates/data_connector/src/components/header.tsx +1 -1
  22. package/templates/data_connector/src/index.tsx +2 -66
  23. package/templates/data_connector/src/{app.tsx → intents/data_connector/app.tsx} +3 -3
  24. package/templates/data_connector/src/{entrypoint.tsx → intents/data_connector/entrypoint.tsx} +5 -5
  25. package/templates/data_connector/src/{home.tsx → intents/data_connector/home.tsx} +1 -1
  26. package/templates/data_connector/src/intents/data_connector/index.tsx +56 -0
  27. package/templates/data_connector/src/pages/error.tsx +1 -1
  28. package/templates/data_connector/src/pages/login.tsx +1 -1
  29. package/templates/data_connector/src/routes/protected_route.tsx +1 -1
  30. package/templates/data_connector/src/routes/routes.tsx +3 -3
  31. package/templates/data_connector/styles/components.css +18 -0
  32. package/templates/gen_ai/backend/server.ts +17 -0
  33. package/templates/gen_ai/canva-app.json +5 -0
  34. package/templates/gen_ai/package.json +10 -8
  35. package/templates/gen_ai/src/api/api.ts +4 -0
  36. package/templates/gen_ai/src/components/footer.tsx +1 -1
  37. package/templates/gen_ai/src/components/loading_results.tsx +1 -1
  38. package/templates/gen_ai/src/components/prompt_input.tsx +1 -1
  39. package/templates/gen_ai/src/index.tsx +3 -14
  40. package/templates/gen_ai/src/{app.tsx → intents/design_editor/app.tsx} +3 -3
  41. package/templates/gen_ai/src/{home.tsx → intents/design_editor/home.tsx} +1 -1
  42. package/templates/gen_ai/src/intents/design_editor/index.tsx +17 -0
  43. package/templates/gen_ai/src/pages/error.tsx +1 -1
  44. package/templates/gen_ai/src/routes/routes.tsx +2 -2
  45. package/templates/gen_ai/styles/components.css +18 -0
  46. package/templates/hello_world/canva-app.json +5 -0
  47. package/templates/hello_world/package.json +10 -8
  48. package/templates/hello_world/src/index.tsx +3 -21
  49. package/templates/hello_world/src/{app.tsx → intents/design_editor/app.tsx} +26 -3
  50. package/templates/hello_world/src/intents/design_editor/index.tsx +25 -0
  51. package/templates/hello_world/src/{tests → intents/design_editor/tests}/app.tests.tsx +19 -13
  52. package/templates/hello_world/styles/components.css +18 -0
  53. package/templates/mls/README.md +81 -0
  54. package/templates/mls/canva-app.json +25 -0
  55. package/templates/mls/declarations/declarations.d.ts +29 -0
  56. package/templates/mls/eslint.config.mjs +14 -0
  57. package/templates/mls/jest.config.mjs +36 -0
  58. package/templates/mls/jest.setup.ts +37 -0
  59. package/templates/mls/package.json +117 -0
  60. package/templates/mls/scripts/copy_env.ts +13 -0
  61. package/templates/mls/scripts/ssl/ssl.ts +131 -0
  62. package/templates/mls/scripts/start/app_runner.ts +223 -0
  63. package/templates/mls/scripts/start/context.ts +171 -0
  64. package/templates/mls/scripts/start/start.ts +46 -0
  65. package/templates/mls/src/__tests__/app.tests.tsx +11 -0
  66. package/templates/mls/src/__tests__/office_selection_page.tests.tsx +72 -0
  67. package/templates/mls/src/__tests__/utils.tsx +19 -0
  68. package/templates/mls/src/adapter.ts +126 -0
  69. package/templates/mls/src/components/agent/agent_card.tsx +57 -0
  70. package/templates/mls/src/components/agent/agent_grid.tsx +37 -0
  71. package/templates/mls/src/components/agent/agent_list.tsx +17 -0
  72. package/templates/mls/src/components/agent/agent_search_filters.tsx +88 -0
  73. package/templates/mls/src/components/breadcrumb/breadcrumb.tsx +40 -0
  74. package/templates/mls/src/components/listing/listing_card.tsx +64 -0
  75. package/templates/mls/src/components/listing/listing_grid.tsx +37 -0
  76. package/templates/mls/src/components/listing/listing_list.tsx +21 -0
  77. package/templates/mls/src/components/listing/listing_search_filters.tsx +145 -0
  78. package/templates/mls/src/components/placeholders/placeholders.tsx +65 -0
  79. package/templates/mls/src/data.ts +359 -0
  80. package/templates/mls/src/index.tsx +4 -0
  81. package/templates/mls/src/intents/design_editor/app.tsx +44 -0
  82. package/templates/mls/src/intents/design_editor/index.tsx +25 -0
  83. package/templates/mls/src/pages/agent_details_page/agent_details_page.tsx +175 -0
  84. package/templates/mls/src/pages/list_page/agent_tab_panel.tsx +126 -0
  85. package/templates/mls/src/pages/list_page/list_page.tsx +67 -0
  86. package/templates/mls/src/pages/list_page/listing_tab_panel.tsx +135 -0
  87. package/templates/mls/src/pages/listing_details_page/listing_details_page.tsx +418 -0
  88. package/templates/mls/src/pages/loading_page/loading_page.tsx +152 -0
  89. package/templates/mls/src/pages/office_selection_page/office_selection_page.tsx +144 -0
  90. package/templates/mls/src/real_estate.type.ts +44 -0
  91. package/templates/mls/src/util/use_add_element.tsx +62 -0
  92. package/templates/mls/src/util/use_drag_element.tsx +68 -0
  93. package/templates/mls/styles/components.css +56 -0
  94. package/templates/mls/tsconfig.json +55 -0
  95. package/templates/mls/webpack.config.ts +254 -0
  96. package/templates/optional/AGENTS.md +80 -2
  97. package/templates/optional/CLAUDE.md +80 -2
  98. package/templates/base/backend/routers/oauth.ts +0 -393
  99. package/templates/base/utils/backend/bearer_middleware/bearer_middleware.ts +0 -99
  100. package/templates/base/utils/backend/bearer_middleware/index.ts +0 -1
  101. package/templates/base/utils/backend/bearer_middleware/tests/bearer_middleware.tests.ts +0 -192
  102. package/templates/base/utils/use_add_element.ts +0 -58
  103. package/templates/base/utils/use_feature_support.ts +0 -28
  104. package/templates/common/utils/backend/base_backend/create.ts +0 -104
  105. package/templates/common/utils/table_wrapper.ts +0 -520
  106. package/templates/common/utils/use_add_element.ts +0 -58
  107. package/templates/common/utils/use_feature_support.ts +0 -28
  108. package/templates/common/utils/use_overlay_hook.ts +0 -76
  109. package/templates/common/utils/use_selection_hook.ts +0 -37
  110. package/templates/gen_ai/backend/database/database.ts +0 -42
  111. package/templates/gen_ai/utils/backend/bearer_middleware/bearer_middleware.ts +0 -99
  112. package/templates/gen_ai/utils/backend/bearer_middleware/index.ts +0 -1
  113. package/templates/hello_world/utils/use_add_element.ts +0 -58
  114. package/templates/hello_world/utils/use_feature_support.ts +0 -28
  115. /package/templates/base/{utils/backend → backend}/base_backend/create.ts +0 -0
  116. /package/templates/base/{utils/backend → backend}/jwt_middleware/index.ts +0 -0
  117. /package/templates/base/{utils/backend → backend}/jwt_middleware/jwt_middleware.ts +0 -0
  118. /package/templates/dam/src/{adapter.ts → intents/design_editor/adapter.ts} +0 -0
  119. /package/templates/dam/src/{app.tsx → intents/design_editor/app.tsx} +0 -0
  120. /package/templates/dam/src/{config.ts → intents/design_editor/config.ts} +0 -0
  121. /package/templates/dam/src/{index.css → intents/design_editor/index.css} +0 -0
  122. /package/templates/data_connector/src/{paths.ts → routes/paths.ts} +0 -0
  123. /package/templates/gen_ai/src/{paths.ts → routes/paths.ts} +0 -0
  124. /package/templates/{common → gen_ai}/utils/backend/jwt_middleware/index.ts +0 -0
  125. /package/templates/{common → gen_ai}/utils/backend/jwt_middleware/jwt_middleware.ts +0 -0
  126. /package/templates/hello_world/src/{tests → intents/design_editor/tests}/__snapshots__/app.tests.tsx.snap +0 -0
@@ -1,37 +0,0 @@
1
- import { selection as designSelection } from "@canva/design";
2
- import type { SelectionEvent, SelectionScope } from "@canva/design";
3
- import { useEffect, useState } from "react";
4
-
5
- /**
6
- * Returns a selection event, representing a user selection of the specified content type. The
7
- * event contains methods to read a snapshot of the selected content, and optionally mutate it.
8
- * This is a reactive value. Calling this multiple times will return different instances
9
- * representing the same selection.
10
- * @param scope The type of content to listen for selection changes on
11
- */
12
- export function useSelection<S extends SelectionScope>(
13
- scope: S,
14
- ): SelectionEvent<S> {
15
- const [selection, setSelection] = useState<SelectionEvent<S>>({
16
- scope,
17
- count: 0,
18
- read() {
19
- return Promise.resolve({
20
- contents: Object.freeze([]),
21
- save() {
22
- return Promise.resolve();
23
- },
24
- });
25
- },
26
- });
27
-
28
- useEffect(() => {
29
- const disposer = designSelection.registerOnChange({
30
- scope,
31
- onChange: setSelection,
32
- });
33
- return disposer;
34
- }, [scope]);
35
-
36
- return selection;
37
- }
@@ -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";
@@ -1,58 +0,0 @@
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 { features } from "@canva/platform";
11
- import { useEffect, useState } from "react";
12
- import { useFeatureSupport } from "./use_feature_support";
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
- // eslint-disable-next-line no-console
34
- console.warn(
35
- "Neither addElementAtPoint nor addElementAtCursor are supported",
36
- );
37
- return Promise.resolve();
38
- };
39
- });
40
-
41
- useEffect(() => {
42
- const addElement = (element: AddElementParams) => {
43
- if (isSupported(addElementAtPoint)) {
44
- return addElementAtPoint(element);
45
- } else if (isSupported(addElementAtCursor)) {
46
- return addElementAtCursor(element);
47
- }
48
- // eslint-disable-next-line no-console
49
- console.warn(
50
- "Neither addElementAtPoint nor addElementAtCursor are supported",
51
- );
52
- return Promise.resolve();
53
- };
54
- setAddElement(() => addElement);
55
- }, [isSupported]);
56
-
57
- return addElement;
58
- };
@@ -1,28 +0,0 @@
1
- import { features } from "@canva/platform";
2
- import type { Feature } from "@canva/platform";
3
- import { useEffect, useState } 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
- }