@osdk/create-app 0.13.0 → 0.14.0-main-20240503154621

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 (48) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/build/js/index.browser.mjs +8 -2
  3. package/build/js/index.browser.mjs.map +1 -1
  4. package/build/js/index.cjs +8 -2
  5. package/build/js/index.cjs.map +1 -1
  6. package/build/js/index.mjs +8 -2
  7. package/build/js/index.mjs.map +1 -1
  8. package/build/types/prompts/promptTemplate.d.ts.map +1 -1
  9. package/build/types/templates.d.ts +1 -0
  10. package/build/types/templates.d.ts.map +1 -1
  11. package/package.json +1 -1
  12. package/templates/template-next-static-export/package.json.hbs +1 -1
  13. package/templates/template-tutorial-todo-app/.eslintrc.cjs +18 -0
  14. package/templates/template-tutorial-todo-app/README.md.hbs +33 -0
  15. package/templates/template-tutorial-todo-app/index.html +13 -0
  16. package/templates/template-tutorial-todo-app/package.json.hbs +31 -0
  17. package/templates/template-tutorial-todo-app/public/todo-app.svg +4 -0
  18. package/templates/template-tutorial-todo-app/src/AuthCallback.tsx +24 -0
  19. package/templates/template-tutorial-todo-app/src/AuthenticatedRoute.tsx +33 -0
  20. package/templates/template-tutorial-todo-app/src/CreateProjectButton.tsx +33 -0
  21. package/templates/template-tutorial-todo-app/src/CreateProjectDialog.tsx +56 -0
  22. package/templates/template-tutorial-todo-app/src/CreateTaskButton.tsx.hbs +35 -0
  23. package/templates/template-tutorial-todo-app/src/CreateTaskDialog.tsx.hbs +52 -0
  24. package/templates/template-tutorial-todo-app/src/DeleteProjectButton.tsx.hbs +34 -0
  25. package/templates/template-tutorial-todo-app/src/DeleteProjectDialog.tsx.hbs +46 -0
  26. package/templates/template-tutorial-todo-app/src/Dialog.module.css +5 -0
  27. package/templates/template-tutorial-todo-app/src/Dialog.tsx +19 -0
  28. package/templates/template-tutorial-todo-app/src/Home.module.css +35 -0
  29. package/templates/template-tutorial-todo-app/src/Home.tsx.hbs +62 -0
  30. package/templates/template-tutorial-todo-app/src/Layout.module.css +16 -0
  31. package/templates/template-tutorial-todo-app/src/Layout.tsx +21 -0
  32. package/templates/template-tutorial-todo-app/src/Login.module.css +5 -0
  33. package/templates/template-tutorial-todo-app/src/Login.tsx +42 -0
  34. package/templates/template-tutorial-todo-app/src/ProjectSelect.tsx.hbs +40 -0
  35. package/templates/template-tutorial-todo-app/src/TaskList.module.css +6 -0
  36. package/templates/template-tutorial-todo-app/src/TaskList.tsx.hbs +38 -0
  37. package/templates/template-tutorial-todo-app/src/TaskListItem.module.css +3 -0
  38. package/templates/template-tutorial-todo-app/src/TaskListItem.tsx.hbs +37 -0
  39. package/templates/template-tutorial-todo-app/src/client.ts.hbs +31 -0
  40. package/templates/template-tutorial-todo-app/src/index.css +73 -0
  41. package/templates/template-tutorial-todo-app/src/main.tsx +33 -0
  42. package/templates/template-tutorial-todo-app/src/mocks.ts.hbs +208 -0
  43. package/templates/template-tutorial-todo-app/src/useProjectTasks.ts.hbs +59 -0
  44. package/templates/template-tutorial-todo-app/src/useProjects.ts.hbs +44 -0
  45. package/templates/template-tutorial-todo-app/src/vite-env.d.ts +1 -0
  46. package/templates/template-tutorial-todo-app/tsconfig.json +25 -0
  47. package/templates/template-tutorial-todo-app/tsconfig.node.json +10 -0
  48. package/templates/template-tutorial-todo-app/vite.config.ts.hbs +19 -0
@@ -0,0 +1,46 @@
1
+ import { OsdkTodoProject } from "{{osdkPackage}}/ontology/objects";
2
+ import { useCallback, useState } from "react";
3
+ import Dialog from "./Dialog";
4
+ import useProjects from "./useProjects";
5
+
6
+ interface DeleteProjectDialogProps {
7
+ project: OsdkTodoProject;
8
+ isOpen: boolean;
9
+ onClose: () => void;
10
+ }
11
+
12
+ function DeleteProjectDialog({
13
+ project,
14
+ isOpen,
15
+ onClose,
16
+ }: DeleteProjectDialogProps) {
17
+ const { deleteProject } = useProjects();
18
+
19
+ const [isDeleting, setIsDeleting] = useState(false);
20
+ const handleSubmit = useCallback(async () => {
21
+ setIsDeleting(true);
22
+ try {
23
+ await deleteProject(project);
24
+ } finally {
25
+ setIsDeleting(false);
26
+ onClose();
27
+ }
28
+ }, [deleteProject, onClose, project]);
29
+
30
+ return (
31
+ <Dialog
32
+ isOpen={isOpen}
33
+ buttons={[
34
+ <button disabled={isDeleting} onClick={handleSubmit}>
35
+ Delete
36
+ </button>,
37
+ <button disabled={isDeleting} onClick={onClose}>
38
+ Cancel
39
+ </button>,
40
+ ]}
41
+ >
42
+ Are you sure you want to delete this project?
43
+ </Dialog>
44
+ );
45
+ }
46
+ export default DeleteProjectDialog;
@@ -0,0 +1,5 @@
1
+ .buttons {
2
+ display: flex;
3
+ gap: 1em;
4
+ margin-top: 1em;
5
+ }
@@ -0,0 +1,19 @@
1
+ import { PropsWithChildren } from "react";
2
+ import css from "./Dialog.module.css";
3
+
4
+ interface DialogProps {
5
+ isOpen: boolean;
6
+ buttons?: React.ReactElement[];
7
+ }
8
+
9
+ function Dialog({ children, isOpen, buttons }: PropsWithChildren<DialogProps>) {
10
+ return (
11
+ <dialog open={isOpen}>
12
+ {children}
13
+ {buttons != null && buttons.length > 0 && (
14
+ <div className={css.buttons}>{buttons}</div>
15
+ )}
16
+ </dialog>
17
+ );
18
+ }
19
+ export default Dialog;
@@ -0,0 +1,35 @@
1
+ .tutorialBannerWrapper {
2
+ display: flex;
3
+ margin: 2em;
4
+ }
5
+
6
+ .tutorialBanner {
7
+ flex: 1;
8
+ width: 0;
9
+ background: #646cff;
10
+ color: #ffffff;
11
+ border-radius: 1em;
12
+ padding: 1em;
13
+ box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
14
+ }
15
+
16
+ .tutorialBannerTitle {
17
+ margin-top: 0;
18
+ font-weight: 600;
19
+ }
20
+
21
+ .projectSelect {
22
+ display: flex;
23
+ align-items: center;
24
+ gap: 1em;
25
+ margin: 2em;
26
+ font-weight: 600;
27
+ }
28
+
29
+ .projectCard {
30
+ margin: 2em;
31
+ }
32
+
33
+ .projectTitle {
34
+ font-size: 1.5em;
35
+ }
@@ -0,0 +1,62 @@
1
+ import { OsdkTodoProject } from "{{osdkPackage}}/ontology/objects";
2
+ import { useCallback, useEffect, useState } from "react";
3
+ import CreateProjectButton from "./CreateProjectButton";
4
+ import CreateTaskButton from "./CreateTaskButton";
5
+ import DeleteProjectButton from "./DeleteProjectButton";
6
+ import css from "./Home.module.css";
7
+ import Layout from "./Layout";
8
+ import ProjectSelect from "./ProjectSelect";
9
+ import TaskList from "./TaskList";
10
+ import useProjects from "./useProjects";
11
+
12
+ function Home() {
13
+ const [projectId, setProjectId] = useState<string | undefined>(undefined);
14
+ const { projects } = useProjects();
15
+ const project = projects?.find((p) => p.id === projectId);
16
+
17
+ const handleSelectProject = useCallback(
18
+ (p: OsdkTodoProject) => setProjectId(p.id),
19
+ [],
20
+ );
21
+
22
+ useEffect(() => {
23
+ if (project == null && projects != null && projects.length > 0) {
24
+ setProjectId(projects[0].id);
25
+ }
26
+ }, [project, projects]);
27
+
28
+ return (
29
+ <Layout>
30
+ <div className={css.tutorialBannerWrapper}>
31
+ <div className={css.tutorialBanner}>
32
+ <p className={css.tutorialBannerTitle}>
33
+ 💡 Welcome to this tutorial!
34
+ </p>
35
+ <p>
36
+ The Todo App below has been implemented with fake in memory data.
37
+ Can you solve how to switch it to use the Ontology SDK instead?
38
+ </p>
39
+ </div>
40
+ </div>
41
+ <div className={css.projectSelect}>
42
+ <span>Project:</span>
43
+ <ProjectSelect
44
+ project={project}
45
+ projects={projects ?? []}
46
+ onSelectProject={handleSelectProject}
47
+ />
48
+ <CreateProjectButton onProjectCreated={setProjectId} />
49
+ {project != null && <DeleteProjectButton project={project} />}
50
+ </div>
51
+ {project != null && (
52
+ <div className={css.projectCard} key={project.id}>
53
+ <h1 className={css.projectTitle}>{project.name}</h1>
54
+ <TaskList project={project} />
55
+ <CreateTaskButton project={project} />
56
+ </div>
57
+ )}
58
+ </Layout>
59
+ );
60
+ }
61
+
62
+ export default Home;
@@ -0,0 +1,16 @@
1
+ .header {
2
+ display: flex;
3
+ align-items: center;
4
+ margin: 2em;
5
+ }
6
+
7
+ .logo {
8
+ height: 4em;
9
+ align-items: center;
10
+ margin-right: 1em;
11
+ }
12
+
13
+ .title {
14
+ font-weight: 600;
15
+ font-size: 1.5em;
16
+ }
@@ -0,0 +1,21 @@
1
+ import todoAppLogo from "/todo-app.svg";
2
+ import React from "react";
3
+ import css from "./Layout.module.css";
4
+
5
+ interface LayoutProps {
6
+ children?: React.ReactNode;
7
+ }
8
+
9
+ function Layout({ children }: LayoutProps) {
10
+ return (
11
+ <>
12
+ <div className={css.header}>
13
+ <img src={todoAppLogo} className={css.logo} alt="Todo App logo" />
14
+ <div className={css.title}>Ontology SDK Tutorial - Todo App</div>
15
+ </div>
16
+ {children}
17
+ </>
18
+ );
19
+ }
20
+
21
+ export default Layout;
@@ -0,0 +1,5 @@
1
+ .loginButton {
2
+ display: flex;
3
+ justify-content: center;
4
+ margin: 2em;
5
+ }
@@ -0,0 +1,42 @@
1
+ import { useCallback, useState } from "react";
2
+ import { Navigate } from "react-router-dom";
3
+ import client from "./client";
4
+ import Layout from "./Layout";
5
+ import css from "./Login.module.css";
6
+
7
+ function Login() {
8
+ const [isLoggingIn, setIsLoggingIn] = useState(false);
9
+ const [error, setError] = useState<string | undefined>(undefined);
10
+ const token = client.auth.token;
11
+
12
+ const handleLogin = useCallback(async () => {
13
+ setIsLoggingIn(true);
14
+ try {
15
+ // Initiate the OAuth flow, which will redirect the user to log into Foundry
16
+ // Once the login has completed, the user will be redirected back to the route defined via the
17
+ // FOUNDRY_REDIRECT_URL variable in .env.development
18
+ await client.auth.signIn();
19
+ } catch (e: unknown) {
20
+ console.error(e);
21
+ setError((e as Error).message ?? e);
22
+ }
23
+ }, []);
24
+
25
+ // If the token exists but a user tries to load /login, redirect to the home page instead
26
+ if (token != null) {
27
+ return <Navigate to="/" replace={true} />;
28
+ }
29
+
30
+ return (
31
+ <Layout>
32
+ <div className={css.loginButton}>
33
+ <button onClick={handleLogin}>
34
+ {isLoggingIn ? "Logging in…" : "Log in "}
35
+ </button>
36
+ </div>
37
+ {error && <div>Unable to log in: {error}</div>}
38
+ </Layout>
39
+ );
40
+ }
41
+
42
+ export default Login;
@@ -0,0 +1,40 @@
1
+ import { OsdkTodoProject } from "{{osdkPackage}}/ontology/objects";
2
+ import { ChangeEvent, useCallback } from "react";
3
+
4
+ interface ProjectSelectProps {
5
+ project: OsdkTodoProject | undefined;
6
+ projects: OsdkTodoProject[];
7
+ onSelectProject: (project: OsdkTodoProject) => void;
8
+ }
9
+
10
+ function ProjectSelect({
11
+ project,
12
+ projects,
13
+ onSelectProject,
14
+ }: ProjectSelectProps) {
15
+ const handleSelect = useCallback(
16
+ (e: ChangeEvent<HTMLSelectElement>) => {
17
+ const nextProject = projects.find((p) => `${p.id}` === e.target.value);
18
+ if (nextProject != null) {
19
+ onSelectProject(nextProject);
20
+ }
21
+ },
22
+ [projects, onSelectProject],
23
+ );
24
+
25
+ return (
26
+ <select value={project?.id} onChange={handleSelect}>
27
+ <option hidden disabled selected>
28
+ -- select a project --
29
+ </option>
30
+
31
+ {projects.map((p) => (
32
+ <option key={p.id} value={p.id}>
33
+ {p.name}
34
+ </option>
35
+ ))}
36
+ </select>
37
+ );
38
+ }
39
+
40
+ export default ProjectSelect;
@@ -0,0 +1,6 @@
1
+ .taskList {
2
+ list-style: none;
3
+ padding: 0;
4
+ margin-top: 1em;
5
+ margin-bottom: 1em;
6
+ }
@@ -0,0 +1,38 @@
1
+ import { OsdkTodoProject } from "{{osdkPackage}}/ontology/objects";
2
+ import css from "./TaskList.module.css";
3
+ import TaskListItem from "./TaskListItem";
4
+ import { useProjectTasks } from "./useProjectTasks";
5
+
6
+ interface TaskListProps {
7
+ project: OsdkTodoProject;
8
+ }
9
+
10
+ function TaskList({ project }: TaskListProps) {
11
+ const {
12
+ tasks,
13
+ isLoading: isLoadingTasks,
14
+ isError: isErrorTasks,
15
+ deleteTask,
16
+ } = useProjectTasks(project);
17
+
18
+ if (isErrorTasks) {
19
+ return <div className={css.taskList}>Error loading tasks!</div>;
20
+ } else if (isLoadingTasks) {
21
+ return null;
22
+ }
23
+
24
+ const data = tasks ?? [];
25
+ if (data.length === 0) {
26
+ return <div className={css.taskList}>No tasks found</div>;
27
+ }
28
+
29
+ return (
30
+ <ul className={css.taskList}>
31
+ {data.map((task) => (
32
+ <TaskListItem key={task.id} task={task} deleteTask={deleteTask} />
33
+ ))}
34
+ </ul>
35
+ );
36
+ }
37
+
38
+ export default TaskList;
@@ -0,0 +1,3 @@
1
+ .label {
2
+ margin-left: 0.5em;
3
+ }
@@ -0,0 +1,37 @@
1
+ import { OsdkTodoTask } from "{{osdkPackage}}/ontology/objects";
2
+ import { useCallback, useState } from "react";
3
+ import css from "./TaskListItem.module.css";
4
+
5
+ interface TaskListItemProps {
6
+ task: OsdkTodoTask;
7
+ deleteTask: (task: OsdkTodoTask) => Promise<void>;
8
+ }
9
+
10
+ function TaskListItem({ task, deleteTask }: TaskListItemProps) {
11
+ const [isDeleting, setIsDeleting] = useState(false);
12
+ const handleClick = useCallback(async () => {
13
+ setIsDeleting(true);
14
+ try {
15
+ await deleteTask(task);
16
+ } finally {
17
+ setIsDeleting(false);
18
+ }
19
+ }, [deleteTask, task]);
20
+
21
+ return (
22
+ <li>
23
+ <input
24
+ id={`${task.id}`}
25
+ type="checkbox"
26
+ onClick={handleClick}
27
+ checked={isDeleting}
28
+ disabled={isDeleting}
29
+ />
30
+ <label className={css.label} htmlFor={`${task.id}`}>
31
+ {task.title}
32
+ </label>
33
+ </li>
34
+ );
35
+ }
36
+
37
+ export default TaskListItem;
@@ -0,0 +1,31 @@
1
+ import { FoundryClient, PublicClientAuth } from "{{osdkPackage}}";
2
+
3
+ const url = import.meta.env.VITE_FOUNDRY_API_URL;
4
+ const clientId = import.meta.env.VITE_FOUNDRY_CLIENT_ID;
5
+ const redirectUrl = import.meta.env.VITE_FOUNDRY_REDIRECT_URL;
6
+ checkEnv(url, "VITE_FOUNDRY_API_URL");
7
+ checkEnv(clientId, "VITE_FOUNDRY_CLIENT_ID");
8
+ checkEnv(redirectUrl, "VITE_FOUNDRY_REDIRECT_URL");
9
+
10
+ function checkEnv(
11
+ value: string | undefined,
12
+ name: string,
13
+ ): asserts value is string {
14
+ if (value == null) {
15
+ throw new Error(`Missing environment variable: ${name}`);
16
+ }
17
+ }
18
+
19
+ /**
20
+ * Initialize the client to interact with the Ontology SDK
21
+ */
22
+ const client = new FoundryClient({
23
+ url,
24
+ auth: new PublicClientAuth({
25
+ clientId,
26
+ url,
27
+ redirectUrl,
28
+ }),
29
+ });
30
+
31
+ export default client;
@@ -0,0 +1,73 @@
1
+ :root {
2
+ font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
3
+ line-height: 1.5;
4
+ font-weight: 400;
5
+
6
+ color-scheme: light dark;
7
+ color: rgba(255, 255, 255, 0.87);
8
+ background-color: #242424;
9
+
10
+ font-synthesis: none;
11
+ text-rendering: optimizeLegibility;
12
+ -webkit-font-smoothing: antialiased;
13
+ -moz-osx-font-smoothing: grayscale;
14
+ }
15
+
16
+ #root {
17
+ max-width: 1280px;
18
+ margin: 2rem auto;
19
+ padding: 2rem;
20
+ }
21
+
22
+ a {
23
+ font-weight: 500;
24
+ color: #646cff;
25
+ text-decoration: inherit;
26
+ }
27
+ a:hover {
28
+ color: #535bf2;
29
+ }
30
+
31
+ body {
32
+ margin: 0;
33
+ display: flex;
34
+ min-width: 320px;
35
+ min-height: 100vh;
36
+ }
37
+
38
+ h1 {
39
+ font-size: 3.2em;
40
+ line-height: 1.1;
41
+ }
42
+
43
+ button {
44
+ border-radius: 8px;
45
+ border: 1px solid transparent;
46
+ padding: 0.6em 1.2em;
47
+ font-size: 1em;
48
+ font-weight: 500;
49
+ font-family: inherit;
50
+ background-color: #1a1a1a;
51
+ cursor: pointer;
52
+ transition: border-color 0.25s;
53
+ }
54
+ button:hover {
55
+ border-color: #646cff;
56
+ }
57
+ button:focus,
58
+ button:focus-visible {
59
+ outline: 4px auto -webkit-focus-ring-color;
60
+ }
61
+
62
+ @media (prefers-color-scheme: light) {
63
+ :root {
64
+ color: #213547;
65
+ background-color: #ffffff;
66
+ }
67
+ a:hover {
68
+ color: #747bff;
69
+ }
70
+ button {
71
+ background-color: #f9f9f9;
72
+ }
73
+ }
@@ -0,0 +1,33 @@
1
+ import ReactDOM from "react-dom/client";
2
+ import { createBrowserRouter, RouterProvider } from "react-router-dom";
3
+ import AuthCallback from "./AuthCallback";
4
+ import AuthenticatedRoute from "./AuthenticatedRoute";
5
+ import Home from "./Home";
6
+ import Login from "./Login";
7
+ import "./index.css";
8
+
9
+ const router = createBrowserRouter([
10
+ {
11
+ path: "/",
12
+ element: <AuthenticatedRoute />,
13
+ children: [
14
+ {
15
+ path: "/",
16
+ element: <Home />,
17
+ },
18
+ ],
19
+ },
20
+ {
21
+ path: "/login",
22
+ element: <Login />,
23
+ },
24
+ {
25
+ // This is the route defined in your application's redirect URL
26
+ path: "/auth/callback",
27
+ element: <AuthCallback />,
28
+ },
29
+ ]);
30
+
31
+ ReactDOM.createRoot(document.getElementById("root")!).render(
32
+ <RouterProvider router={router} />,
33
+ );