Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

Shared tokens UI + Api (#894)

Ivan Starkov8e5d0a2186ef
diff --git a/apps/designer/app/dashboard/projects/create-project.tsx b/apps/designer/app/dashboard/projects/create-project.tsx
index 70646f41d5..7a59c42aa7 100644
--- a/apps/designer/app/dashboard/projects/create-project.tsx
+++ b/apps/designer/app/dashboard/projects/create-project.tsx
@@ -18,7 +18,7 @@ import { DialogActions, DialogClose, Dialog } from "./dialog";
const trpc = createTrpcRemixProxy<DashboardProjectRouter>(dashboardProjectPath);
const useForm = () => {
- const { submit, data } = trpc.create.useMutation();
+ const { send, data } = trpc.create.useMutation();
const navigate = useNavigate();
useEffect(() => {
@@ -32,7 +32,7 @@ const useForm = () => {
event.preventDefault();
const formData = new FormData(event.currentTarget as HTMLFormElement);
const title = String(formData.get("title") ?? "");
- submit({ title });
+ send({ title });
};
return {
diff --git a/apps/designer/app/dashboard/projects/project-card.tsx b/apps/designer/app/dashboard/projects/project-card.tsx
index e42fdf3942..5d93ec7fce 100644
--- a/apps/designer/app/dashboard/projects/project-card.tsx
+++ b/apps/designer/app/dashboard/projects/project-card.tsx
@@ -144,9 +144,9 @@ const Menu = ({
const useProjectCard = () => {
const fetcher = useFetcher();
const thumbnailRef = useRef<HTMLAnchorElement>(null);
- const { submit: deleteProject } = trpc.delete.useMutation();
- const { submit: rename } = trpc.rename.useMutation();
- const { submit: duplicate } = trpc.duplicate.useMutation();
+ const { send: deleteProject } = trpc.delete.useMutation();
+ const { send: rename } = trpc.rename.useMutation();
+ const { send: duplicate } = trpc.duplicate.useMutation();
// @todo with dialog it can be displayed in the dialog
useEffect(() => {
diff --git a/apps/designer/app/designer/designer.tsx b/apps/designer/app/designer/designer.tsx
index 89d458c0e2..03e29f881b 100644
--- a/apps/designer/app/designer/designer.tsx
+++ b/apps/designer/app/designer/designer.tsx
@@ -37,7 +37,7 @@ import {
} from "~/shared/nano-states";
import { useClientSettings } from "./shared/client-settings";
import { Navigator } from "./features/sidebar-left";
-import { getBuildUrl } from "~/shared/router-utils";
+import { designerUrl, getBuildUrl } from "~/shared/router-utils";
import { useInstanceCopyPaste } from "~/shared/copy-paste";
import { AssetsProvider, usePublishAssets } from "./shared/assets";
@@ -275,10 +275,7 @@ export type DesignerProps = {
buildId: string;
buildOrigin: string;
authReadToken: string;
- authSharedTokens: {
- token: string;
- relation: "viewers" | "editors" | "owner";
- }[];
+ authToken?: string;
};
export const Designer = ({
@@ -289,7 +286,7 @@ export const Designer = ({
buildId,
buildOrigin,
authReadToken,
- authSharedTokens,
+ authToken,
}: DesignerProps) => {
useSubscribeBreakpoints();
useSetProject(project);
@@ -297,7 +294,7 @@ export const Designer = ({
useSetCurrentPageId(pageId);
const [publish, publishRef] = usePublish();
useDesignerStore(publish);
- useSyncServer({ buildId, treeId, projectId: project.id });
+ useSyncServer({ buildId, treeId, projectId: project.id, authToken });
usePublishAssets(publish);
const [isPreviewMode] = useIsPreviewMode();
usePublishShortcuts(publish);
@@ -332,15 +329,6 @@ export const Designer = ({
authReadToken,
});
- const previewUrl = getBuildUrl({
- buildOrigin,
- project,
- page,
- mode: "preview",
- // Temporary solution until the new share UI is implemented
- authToken: authSharedTokens.find((t) => t.relation === "viewers")?.token,
- });
-
return (
<AssetsProvider>
<ChromeWrapper isPreviewMode={isPreviewMode}>
@@ -348,7 +336,15 @@ export const Designer = ({
css={{ gridArea: "header" }}
project={project}
publish={publish}
- previewUrl={previewUrl}
+ designerUrl={({ authToken, mode }) =>
+ designerUrl({
+ projectId: project.id,
+ pageId: page.id,
+ origin: window.location.origin,
+ authToken,
+ mode,
+ })
+ }
/>
<Main>
<Workspace onTransitionEnd={onTransitionEnd} publish={publish}>
diff --git a/apps/designer/app/designer/features/topbar/share.tsx b/apps/designer/app/designer/features/topbar/share.tsx
index 136d0ec293..eef15b0c91 100644
--- a/apps/designer/app/designer/features/topbar/share.tsx
+++ b/apps/designer/app/designer/features/topbar/share.tsx
@@ -1,75 +1,126 @@
import {
Button,
- DeprecatedIconButton,
- DeprecatedPopover,
- DeprecatedPopoverTrigger,
- DeprecatedPopoverContent,
- DeprecatedPopoverPortal,
+ FloatingPanelPopover,
+ FloatingPanelPopoverContent,
+ FloatingPanelPopoverTitle,
+ FloatingPanelPopoverTrigger,
+ theme,
+ css,
} from "@webstudio-is/design-system";
-import { Share1Icon } from "@webstudio-is/icons";
-import { useIsShareDialogOpen } from "../../shared/nano-states";
-import { theme } from "@webstudio-is/design-system";
+import { useProject } from "../../shared/nano-states";
import {
- ShareProjectDeprecated,
ShareProject,
LinkOptions,
+ type ShareProjectProps,
} from "~/shared/share-project";
+import { createTrpcRemixProxy } from "~/shared/remix/trpc-remix-proxy";
+import type { AuthorizationTokensRouter } from "@webstudio-is/authorization-token";
+import { authorizationTokenPath } from "~/shared/router-utils";
+import { useEffect } from "react";
+import { useDebouncedCallback } from "use-debounce";
-type ShareButtonDeprecatedProps = {
- url: string;
-};
+const trpc = createTrpcRemixProxy<AuthorizationTokensRouter>(
+ authorizationTokenPath
+);
-const Content = ({ url }: ShareButtonDeprecatedProps) => {
- if (typeof location === "undefined") {
- return null;
- }
- return (
- <DeprecatedPopoverContent
- css={{ padding: theme.spacing[9] }}
- hideArrow={true}
- onFocusOutside={(event) => {
- // Used to prevent closing when opened from the main dropdown menu
- event.preventDefault();
- }}
- >
- <ShareProjectDeprecated url={url} />
- </DeprecatedPopoverContent>
- );
+export type ShareButtonProps = {
+ designerUrl: ShareProjectProps["designerUrl"];
};
-export const ShareButtonDeprecated = (props: ShareButtonDeprecatedProps) => {
- const [isOpen, setIsOpen] = useIsShareDialogOpen();
- return (
- <DeprecatedPopover open={isOpen} onOpenChange={setIsOpen}>
- <DeprecatedPopoverTrigger asChild aria-label="Share project">
- <DeprecatedIconButton>
- <Share1Icon />
- </DeprecatedIconButton>
- </DeprecatedPopoverTrigger>
- <DeprecatedPopoverPortal>
- <Content {...props} />
- </DeprecatedPopoverPortal>
- </DeprecatedPopover>
- );
-};
+const useShareProjectContainer = () => {
+ const { data: links, load } = trpc.findMany.useQuery();
+ const { send: createToken } = trpc.create.useMutation();
+ const { send: removeToken } = trpc.remove.useMutation();
+ const { send: updateToken } = trpc.update.useMutation();
+
+ const [project] = useProject();
+ const projectId = project?.id;
+
+ useEffect(() => {
+ if (projectId === undefined) {
+ return;
+ }
+
+ load({ projectId });
+ }, [load, projectId]);
+
+ const handleChangeDebounced = useDebouncedCallback((link: LinkOptions) => {
+ if (projectId === undefined) {
+ return;
+ }
+ updateToken({
+ projectId: projectId,
+ token: link.token,
+ relation: link.relation,
+ name: link.name,
+ });
+ }, 100);
-export const ShareButton = () => {
- const handleChange = (link: LinkOptions) => {
- // @todo implement
- };
const handleDelete = (link: LinkOptions) => {
- // @todo implement
+ if (projectId === undefined) {
+ return;
+ }
+
+ removeToken({ projectId: projectId, token: link.token });
};
+
const handleCreate = () => {
- // @todo implement
+ if (projectId === undefined) {
+ return;
+ }
+
+ createToken({
+ projectId: projectId,
+ relation: "viewers",
+ name: "Custom link",
+ });
+ };
+
+ return {
+ links,
+ handleChangeDebounced,
+ handleDelete,
+ handleCreate,
};
+};
+
+/**
+ * we place the logic inside Popover so that the fetcher does not exist outside of it.
+ * Then remix will not call `trpc.findMany.useQuery` if Popover is closed
+ */
+const ShareProjectContainer = ({ designerUrl }: ShareButtonProps) => {
+ const {
+ links,
+ // handleChange,
+ handleChangeDebounced,
+ handleDelete,
+ handleCreate,
+ } = useShareProjectContainer();
+
return (
<ShareProject
- onChange={handleChange}
+ links={links}
+ onChange={handleChangeDebounced}
onDelete={handleDelete}
onCreate={handleCreate}
- >
- <Button>Share</Button>
- </ShareProject>
+ designerUrl={designerUrl}
+ />
+ );
+};
+
+const classZIndex = css({ zIndex: theme.zIndices[1] });
+
+export const ShareButton = ({ designerUrl }: ShareButtonProps) => {
+ return (
+ <FloatingPanelPopover modal>
+ <FloatingPanelPopoverTrigger asChild>
+ <Button>Share</Button>
+ </FloatingPanelPopoverTrigger>
+
+ <FloatingPanelPopoverContent className={classZIndex()}>
+ <ShareProjectContainer designerUrl={designerUrl} />
+ <FloatingPanelPopoverTitle>Share</FloatingPanelPopoverTitle>
+ </FloatingPanelPopoverContent>
+ </FloatingPanelPopover>
);
};
diff --git a/apps/designer/app/designer/features/topbar/topbar.tsx b/apps/designer/app/designer/features/topbar/topbar.tsx
index e2c4283811..06f405090b 100644
--- a/apps/designer/app/designer/features/topbar/topbar.tsx
+++ b/apps/designer/app/designer/features/topbar/topbar.tsx
@@ -1,7 +1,7 @@
import type { Publish } from "~/shared/pubsub";
import { darkTheme, Flex, type CSS } from "@webstudio-is/design-system";
import { PreviewButton } from "./preview";
-import { ShareButton, ShareButtonDeprecated } from "./share";
+import { ShareButton, type ShareButtonProps } from "./share";
import { PublishButton } from "./publish";
import { SyncStatus } from "./sync-status";
import { Menu } from "./menu";
@@ -14,9 +14,9 @@ type TopbarProps = {
css: CSS;
project: Project;
publish: Publish;
- previewUrl: string;
+ designerUrl: ShareButtonProps["designerUrl"];
};
-export const Topbar = ({ css, project, publish, previewUrl }: TopbarProps) => {
+export const Topbar = ({ css, project, publish, designerUrl }: TopbarProps) => {
return (
<Flex
className={darkTheme}
@@ -56,8 +56,9 @@ export const Topbar = ({ css, project, publish, previewUrl }: TopbarProps) => {
>
<SyncStatus />
<PreviewButton publish={publish} />
- <ShareButtonDeprecated url={previewUrl} />
- {isFeatureEnabled("share2") && <ShareButton />}
+ {isFeatureEnabled("share2") && (
+ <ShareButton designerUrl={designerUrl} />
+ )}
<PublishButton project={project} />
</Flex>
</Flex>
diff --git a/apps/designer/app/designer/shared/assets/use-assets.tsx b/apps/designer/app/designer/shared/assets/use-assets.tsx
index ea2411f3d3..21ab6fbee8 100644
--- a/apps/designer/app/designer/shared/assets/use-assets.tsx
+++ b/apps/designer/app/designer/shared/assets/use-assets.tsx
@@ -141,7 +141,7 @@ const Context = createContext<AssetsContext | undefined>(undefined);
export const AssetsProvider = ({ children }: { children: ReactNode }) => {
const [project] = useProject();
const [assetContainers, setAssetContainers] = useAssetsContainer();
- const { load, data: serverAssets } = useFetcher<Asset[]>();
+ const { submit: load, data: serverAssets } = useFetcher<Asset[]>();
const submit = usePersistentFetcher();
const assetContainersRef = useRef(assetContainers);
@@ -150,7 +150,11 @@ export const AssetsProvider = ({ children }: { children: ReactNode }) => {
useEffect(() => {
if (action && assetContainers.length === 0) {
- load(action);
+ /**
+ * To prevent the AssetsProvider from being redrawn every time an action is requested, we use PUT instead of GET
+ * to load assets. The only reason PUT is chosen is that it is idempotent and has not been used before.
+ */
+ load({}, { action, method: "put" });
}
}, [action, assetContainers.length, load]);
@@ -172,7 +176,7 @@ export const AssetsProvider = ({ children }: { children: ReactNode }) => {
// We can't remove it here optimistically because the previous load
// can return it as "updated" because of the async operation nature
if (action) {
- load(action);
+ load({}, { action, method: "put" });
}
if (data.status === "error") {
@@ -200,7 +204,7 @@ export const AssetsProvider = ({ children }: { children: ReactNode }) => {
const assetContainers = assetContainersRef.current;
if (action) {
- load(action);
+ load({}, { action, method: "put" });
}
if (data.status === "error" || data.errors !== undefined) {
diff --git a/apps/designer/app/designer/shared/sync/sync-server.ts b/apps/designer/app/designer/shared/sync/sync-server.ts
index 780e936f6e..983ab02cea 100644
--- a/apps/designer/app/designer/shared/sync/sync-server.ts
+++ b/apps/designer/app/designer/shared/sync/sync-server.ts
@@ -43,6 +43,7 @@ const useNewEntriesCheck = ({
treeId,
buildId,
projectId,
+ authToken,
}: UserSyncServerProps) => {
useEffect(() => {
// @todo setInterval can be completely avoided.
@@ -57,7 +58,7 @@ const useNewEntriesCheck = ({
}
enqueue(() =>
- fetch(restPatchPath(), {
+ fetch(restPatchPath({ authToken }), {
method: "post",
body: JSON.stringify({
transactions,
@@ -70,13 +71,14 @@ const useNewEntriesCheck = ({
}, NEW_ENTRIES_INTERVAL);
return () => clearInterval(intervalId);
- }, [treeId, buildId, projectId]);
+ }, [treeId, buildId, projectId, authToken]);
};
type UserSyncServerProps = {
buildId: Build["id"];
treeId: Tree["id"];
projectId: Project["id"];
+ authToken: string | undefined;
};
export const useSyncServer = (props: UserSyncServerProps) => {
diff --git a/apps/designer/app/routes/$.tsx b/apps/designer/app/routes/$.tsx
index e826bddf9c..c577cd5593 100644
--- a/apps/designer/app/routes/$.tsx
+++ b/apps/designer/app/routes/$.tsx
@@ -50,7 +50,9 @@ export const meta: MetaFunction = ({ data }: { data: Data }) => {
export const loader = async ({ request }: LoaderArgs): Promise<Data> => {
const buildParams = getBuildParams(request);
- const context = await createContext(request);
+ const buildEnv = buildParams?.mode === "published" ? "prod" : "dev";
+
+ const context = await createContext(request, buildEnv);
if (buildParams === undefined) {
throw redirect(dashboardPath());
@@ -66,7 +68,7 @@ export const loader = async ({ request }: LoaderArgs): Promise<Data> => {
const canvasData = await loadCanvasData(
project,
- mode === "published" ? "prod" : "dev",
+ buildEnv,
"pageId" in buildParams ? buildParams.pageId : buildParams.pagePath
);
diff --git a/apps/designer/app/routes/dashboard/index.tsx b/apps/designer/app/routes/dashboard/index.tsx
index 4d65463c52..348c5301c1 100644
--- a/apps/designer/app/routes/dashboard/index.tsx
+++ b/apps/designer/app/routes/dashboard/index.tsx
@@ -9,7 +9,6 @@ import { sentryException } from "~/shared/sentry";
import { ErrorMessage } from "~/shared/error";
import { dashboardProjectRouter } from "@webstudio-is/dashboard/server";
import { createContext } from "~/shared/context.server";
-
export { links } from "~/dashboard";
export const loader = async ({
diff --git a/apps/designer/app/routes/designer.tsx b/apps/designer/app/routes/designer.tsx
index 429a9a5a2e..944712fb5b 100644
--- a/apps/designer/app/routes/designer.tsx
+++ b/apps/designer/app/routes/designer.tsx
@@ -2,6 +2,7 @@ import type { LoaderArgs, MetaFunction } from "@remix-run/node";
import { Root } from "~/shared/remix";
import env from "~/env.server";
import { getThemeData } from "~/shared/theme";
+import type { ShouldRevalidateFunction } from "@remix-run/react";
export const loader = async ({ request }: LoaderArgs) => {
return {
@@ -14,4 +15,16 @@ export const meta: MetaFunction = () => {
return { title: "Webstudio" };
};
+/**
+ * We do not want trpc and other mutations that use the Remix useFetcher hook
+ * to cause a reload of all designer data.
+ */
+export const shouldRevalidate: ShouldRevalidateFunction = ({
+ currentUrl,
+ nextUrl,
+ defaultShouldRevalidate,
+}) => {
+ return currentUrl.href === nextUrl.href ? false : defaultShouldRevalidate;
+};
+
export default Root;
diff --git a/apps/designer/app/routes/designer/$projectId.tsx b/apps/designer/app/routes/designer/$projectId.tsx
index 754e6cd38c..8d47be39ea 100644
--- a/apps/designer/app/routes/designer/$projectId.tsx
+++ b/apps/designer/app/routes/designer/$projectId.tsx
@@ -6,7 +6,7 @@ import { ErrorMessage } from "~/shared/error";
import { sentryException } from "~/shared/sentry";
import { getBuildOrigin } from "~/shared/router-utils";
import { createContext, createAuthReadToken } from "~/shared/context.server";
-import { trpcClient } from "~/services/trpc.server";
+import type { ShouldRevalidateFunction } from "@remix-run/react";
export { links };
@@ -36,22 +36,7 @@ export const loader = async ({
pages.pages.find((page) => page.id === pageIdParam) ?? pages.homePage;
const authReadToken = await createAuthReadToken({ projectId: project.id });
-
- const projectSubjectSets = await trpcClient.authorize.expandLeafNodes.query({
- id: project.id,
- namespace: "Project",
- });
-
- const authSharedTokens: DesignerProps["authSharedTokens"] = [];
-
- for (const subjectSet of projectSubjectSets) {
- if (subjectSet.namespace === "Token") {
- authSharedTokens.push({
- token: subjectSet.id,
- relation: subjectSet.relation,
- });
- }
- }
+ const authToken = url.searchParams.get("authToken") ?? undefined;
return {
project,
@@ -61,7 +46,7 @@ export const loader = async ({
buildId: devBuild.id,
buildOrigin: getBuildOrigin(request),
authReadToken,
- authSharedTokens,
+ authToken,
};
};
@@ -77,4 +62,16 @@ export const DesignerRoute = () => {
return <Designer {...data} />;
};
+/**
+ * We do not want trpc and other mutations that use the Remix useFetcher hook
+ * to cause a reload of all designer data.
+ */
+export const shouldRevalidate: ShouldRevalidateFunction = ({
+ currentUrl,
+ nextUrl,
+ defaultShouldRevalidate,
+}) => {
+ return currentUrl.href === nextUrl.href ? false : defaultShouldRevalidate;
+};
+
export default DesignerRoute;
diff --git a/apps/designer/app/routes/rest/assets.$projectId.tsx b/apps/designer/app/routes/rest/assets.$projectId.tsx
index 7acd1dd261..0621973a69 100644
--- a/apps/designer/app/routes/rest/assets.$projectId.tsx
+++ b/apps/designer/app/routes/rest/assets.$projectId.tsx
@@ -23,14 +23,23 @@ export const loader = async ({ params }: LoaderArgs): Promise<Array<Asset>> => {
return await loadByProject(params.projectId);
};
-export const action = async ({
- request,
- params,
-}: ActionArgs): Promise<ActionData | undefined> => {
+export const action = async (
+ props: ActionArgs
+): Promise<ActionData | Array<Asset> | undefined> => {
+ const { request, params } = props;
+
if (params.projectId === undefined) {
throw new Error("Project id undefined");
}
try {
+ /**
+ * To prevent the AssetsProvider from being redrawn every time an action is requested, we use PUT instead of GET
+ * to load assets. The only reason PUT is chosen is that it is idempotent and has not been used before.
+ */
+ if (request.method === "PUT") {
+ return await loader(props);
+ }
+
if (request.method === "DELETE") {
const { assetId: ids } = DeleteAssets.parse(await request.formData());
const deletedAssets = await deleteAssets(ids);
diff --git a/apps/designer/app/routes/rest/authorization-token.$method.ts b/apps/designer/app/routes/rest/authorization-token.$method.ts
new file mode 100644
index 0000000000..007f7b6093
--- /dev/null
+++ b/apps/designer/app/routes/rest/authorization-token.$method.ts
@@ -0,0 +1,23 @@
+import type { ActionArgs } from "@remix-run/node";
+import { authorizationTokenRouter } from "@webstudio-is/authorization-token/server";
+import { findAuthenticatedUser } from "~/services/auth.server";
+import { createContext } from "~/shared/context.server";
+import { handleTrpcRemixAction } from "~/shared/remix/trpc-remix-request.server";
+
+export const action = async ({ request, params }: ActionArgs) => {
+ const authenticatedUser = await findAuthenticatedUser(request);
+ if (authenticatedUser === null) {
+ throw new Error("Not authenticated");
+ }
+
+ const context = await createContext(request);
+
+ return await handleTrpcRemixAction({
+ request,
+ params,
+ router: authorizationTokenRouter,
+ context,
+ });
+};
+
+export const loader = action;
diff --git a/apps/designer/app/shared/context.server.ts b/apps/designer/app/shared/context.server.ts
index 99704ceadc..3669339ef4 100644
--- a/apps/designer/app/shared/context.server.ts
+++ b/apps/designer/app/shared/context.server.ts
@@ -3,7 +3,6 @@ import { z } from "zod";
import * as cryptoJson from "./crypto/crypto-json.server";
import { authenticator } from "~/services/auth.server";
import { trpcClient } from "~/services/trpc.server";
-import { getMode } from "./router-utils/build-params";
const AuthReadToken = z.object({
projectId: z.string(),
@@ -12,12 +11,11 @@ const AuthReadToken = z.object({
type AuthReadToken = z.infer<typeof AuthReadToken>;
const createAuthorizationContext = async (
- request: Request
+ request: Request,
+ buildEnv: AppContext["authorization"]["buildEnv"]
): Promise<AppContext["authorization"]> => {
const url = new URL(request.url);
- const buildMode = getMode(url);
-
const authReadTokenRaw = url.searchParams.get("authReadToken") ?? undefined;
const authToken = url.searchParams.get("authToken") ?? url.hostname;
@@ -38,7 +36,7 @@ const createAuthorizationContext = async (
userId: user?.id,
authReadToken,
authToken,
- buildEnv: buildMode === "published" ? "prod" : "dev",
+ buildEnv,
authorizeTrpc: trpcClient.authorize,
};
@@ -49,8 +47,14 @@ export const createAuthReadToken = async (tokenData: AuthReadToken) => {
return cryptoJson.encode(tokenData, process.env.AUTH_SECRET ?? "NO-SECRET");
};
-export const createContext = async (request: Request): Promise<AppContext> => {
- const authorization = await createAuthorizationContext(request);
+/**
+ * argument buildEnv==="prod" only if we are loading project with production build
+ */
+export const createContext = async (
+ request: Request,
+ buildEnv: AppContext["authorization"]["buildEnv"] = "dev"
+): Promise<AppContext> => {
+ const authorization = await createAuthorizationContext(request, buildEnv);
return {
authorization,
diff --git a/apps/designer/app/shared/remix/trpc-remix-proxy.ts b/apps/designer/app/shared/remix/trpc-remix-proxy.ts
index 7a939e7a4e..c8a161189c 100644
--- a/apps/designer/app/shared/remix/trpc-remix-proxy.ts
+++ b/apps/designer/app/shared/remix/trpc-remix-proxy.ts
@@ -7,6 +7,7 @@ import type {
} from "@trpc/server";
// eslint-disable-next-line import/no-internal-modules
import { createRecursiveProxy } from "@trpc/server/shared";
+import { useCallback } from "react";
export const createTrpcRemixProxy = <Router extends AnyRouter>(
getPath: (method: string) => string
@@ -14,35 +15,48 @@ export const createTrpcRemixProxy = <Router extends AnyRouter>(
[Procedure in keyof Router["_def"]["record"]]: Router["_def"]["record"][Procedure] extends AnyMutationProcedure
? {
useMutation: () => {
- submit: (input: inferRouterInputs<Router>[Procedure]) => void;
+ send: (input: inferRouterInputs<Router>[Procedure]) => void;
data?: inferRouterOutputs<Router>[Procedure];
+ state: "idle" | "loading" | "submitting";
};
}
: {
useQuery: () => {
load: (input: inferRouterInputs<Router>[Procedure]) => void;
data?: inferRouterOutputs<Router>[Procedure];
+ state: "idle" | "loading" | "submitting";
};
};
} =>
createRecursiveProxy((options) => {
const path = [...options.path];
const hook = path.pop();
+ const { data, submit, state } = useFetcher();
if (hook !== "useMutation" && hook !== "useQuery") {
throw new Error(`Invalid hook ${hook}`);
}
- const fetcher = useFetcher();
-
const method = path.join(".");
- const submit = (input: never) => {
- return fetcher.submit(input, {
- method: hook === "useMutation" ? "post" : "get",
- action: getPath(method),
- });
- };
+ const remixSubmit = useCallback(
+ (input: never) => {
+ return submit(
+ // stringify input as otherwise we loose type safety
+ // (remix will add key: values as FormData entries or as SearchParams
+ { input: JSON.stringify(input) },
+ {
+ method: hook === "useMutation" ? "post" : "get",
+ action: getPath(method),
+ }
+ );
+ },
+ [submit, hook, method]
+ );
- return { submit, data: fetcher.data };
+ return {
+ [hook === "useMutation" ? "send" : "load"]: remixSubmit,
+ data: data,
+ state,
+ };
}) as never;
diff --git a/apps/designer/app/shared/remix/trpc-remix-request.server.ts b/apps/designer/app/shared/remix/trpc-remix-request.server.ts
index a41cb0e4af..aba384e0bd 100644
--- a/apps/designer/app/shared/remix/trpc-remix-request.server.ts
+++ b/apps/designer/app/shared/remix/trpc-remix-request.server.ts
@@ -18,7 +18,24 @@ export const handleTrpcRemixAction = async <Router extends AnyRouter>({
throw new Error("Missing method");
}
- const data = Object.fromEntries(await request.formData()) as never;
+ let input: never;
+
+ if (request.method === "GET") {
+ const url = new URL(request.url);
+ const inputRaw = url.searchParams.get("input");
+ if (typeof inputRaw !== "string") {
+ throw new Error(`Bad method name ${inputRaw}`);
+ }
+ input = JSON.parse(inputRaw) as never;
+ } else {
+ const formData = await request.formData();
+ const inputRaw = formData.get("input");
+ if (typeof inputRaw !== "string") {
+ throw new Error(`Bad method name ${inputRaw}`);
+ }
+ input = JSON.parse(inputRaw) as never;
+ }
+
const caller = router.createCaller(context);
const allowedProcedures = Object.keys(router["_def"].record);
@@ -29,7 +46,7 @@ export const handleTrpcRemixAction = async <Router extends AnyRouter>({
const fn = caller[method];
if (typeof fn === "function") {
- return await fn(data);
+ return await fn(input);
}
throw new Error(`Unknown RPC method "${method}"`);
diff --git a/apps/designer/app/shared/router-utils/build-params.ts b/apps/designer/app/shared/router-utils/build-params.ts
index 0d66607219..792ed3a9d4 100644
--- a/apps/designer/app/shared/router-utils/build-params.ts
+++ b/apps/designer/app/shared/router-utils/build-params.ts
@@ -22,7 +22,7 @@ export const getMode = (url: URL): BuildMode => {
return mode;
};
-const getRequestHost = (request: MinimalRequest): string =>
+export const getRequestHost = (request: MinimalRequest): string =>
request.headers.get("x-forwarded-host") || request.headers.get("host") || "";
const isLocalhost = (host: string) => {
diff --git a/apps/designer/app/shared/router-utils/path-utils.ts b/apps/designer/app/shared/router-utils/path-utils.ts
index 438790f11e..56ab4288d6 100644
--- a/apps/designer/app/shared/router-utils/path-utils.ts
+++ b/apps/designer/app/shared/router-utils/path-utils.ts
@@ -23,6 +23,27 @@ export const designerPath = ({
pageId?: string;
}) => `/designer/${projectId}${searchParams({ pageId })}`;
+export const designerUrl = (props: {
+ projectId: string;
+ pageId?: string;
+ origin: string;
+ authToken?: string;
+ mode?: "edit" | "preview";
+}) => {
+ const { projectId, pageId } = props;
+ const url = new URL(designerPath({ projectId, pageId }), props.origin);
+
+ if (props.authToken !== undefined) {
+ url.searchParams.set("authToken", props.authToken);
+ }
+
+ if (props.mode !== undefined) {
+ url.searchParams.set("mode", props.mode);
+ }
+
+ return url.href;
+};
+
export const dashboardPath = () => {
return "/dashboard";
};
@@ -30,6 +51,9 @@ export const dashboardPath = () => {
export const dashboardProjectPath = (method: string) =>
`/dashboard/projects/${method}`;
+export const authorizationTokenPath = (method: string) =>
+ `/rest/authorization-token/${method}`;
+
export const loginPath = (params: {
error?: typeof AUTH_PROVIDERS[keyof typeof AUTH_PROVIDERS];
message?: string;
@@ -59,7 +83,18 @@ export const restAssetsPath = ({ projectId }: { projectId: string }) =>
export const restThemePath = ({ setting }: { setting: ThemeSetting }) =>
`/rest/theme/${setting}`;
-export const restPatchPath = () => "/rest/patch";
+export const restPatchPath = (props: { authToken?: string }) => {
+ const urlSearchParams = new URLSearchParams();
+ if (props.authToken !== undefined) {
+ urlSearchParams.set("authToken", props.authToken);
+ }
+
+ const urlSearchParamsString = urlSearchParams.toString();
+
+ return `/rest/patch${
+ urlSearchParamsString ? `?${urlSearchParamsString}` : ""
+ }`;
+};
export const restPublishPath = () => "/rest/publish";
diff --git a/apps/designer/app/shared/share-project/index.ts b/apps/designer/app/shared/share-project/index.ts
index bc7d2e6a7a..fb032f9ce3 100644
--- a/apps/designer/app/shared/share-project/index.ts
+++ b/apps/designer/app/shared/share-project/index.ts
@@ -1,2 +1,2 @@
export { ShareProject as ShareProjectDeprecated } from "./share-project";
-export * from "./share-project2";
+export * from "./share-project";
diff --git a/apps/designer/app/shared/share-project/share-project.stories.tsx b/apps/designer/app/shared/share-project/share-project.stories.tsx
index 5b4ac678e4..2b6cd9f251 100644
--- a/apps/designer/app/shared/share-project/share-project.stories.tsx
+++ b/apps/designer/app/shared/share-project/share-project.stories.tsx
@@ -1,8 +1,13 @@
import { v4 as uuid } from "uuid";
import type { ComponentStory } from "@storybook/react";
-import { Button } from "@webstudio-is/design-system";
-import { useState } from "react";
-import { type LinkOptions, ShareProject } from "./share-project2";
+import {
+ Button,
+ FloatingPanelPopover,
+ FloatingPanelPopoverContent,
+ FloatingPanelPopoverTrigger,
+} from "@webstudio-is/design-system";
+import { useEffect, useState } from "react";
+import { type LinkOptions, ShareProject } from "./share-project";
export default {
component: ShareProject,
@@ -10,60 +15,121 @@ export default {
const initialLinks: Array<LinkOptions> = [
{
- url: `https://google.com/${uuid()}`,
+ token: uuid(),
name: "View Only",
- permission: "view",
+ relation: "viewers",
},
{
- url: `https://google.com/${uuid()}`,
+ token: uuid(),
name: "View and Edit",
- permission: "edit",
+ relation: "editors",
},
{
- url: `https://google.com/${uuid()}`,
+ token: uuid(),
name: "Build",
- permission: "build",
+ relation: "builders",
},
];
-const useShareProject = (initialLinks: Array<LinkOptions> = []) => {
- const [links, setLinks] = useState(initialLinks);
+const INITIAL_LINKS: LinkOptions[] = [];
+
+const useShareProject = (
+ initialLinks: Array<LinkOptions> = INITIAL_LINKS,
+ async = false
+) => {
+ const [links, setLinks] = useState(async ? [] : initialLinks);
const onChange = (updatedLink: LinkOptions) => {
setLinks(
- links.map((link) => (link.url === updatedLink.url ? updatedLink : link))
+ links.map((link) =>
+ link.token === updatedLink.token ? updatedLink : link
+ )
);
};
const onDelete = (deletedLink: LinkOptions) => {
- setLinks(links.filter((link) => link.url !== deletedLink.url));
+ setLinks(links.filter((link) => link.token !== deletedLink.token));
};
const onCreate = () => {
setLinks([
...links,
{
- url: `https://google.com/${uuid()}`,
+ token: uuid(),
name: "Custom Link",
- permission: "view",
+ relation: "viewers",
},
]);
};
+
+ useEffect(() => {
+ if (async) {
+ setTimeout(() => {
+ setLinks(initialLinks);
+ }, 1000);
+ return;
+ }
+
+ setLinks(initialLinks);
+ }, [async, initialLinks]);
+
return { links, onChange, onDelete, onCreate };
};
export const Empty: ComponentStory<typeof ShareProject> = () => {
const props = useShareProject();
return (
- <ShareProject {...props} isOpen>
- <Button>Share</Button>
- </ShareProject>
+ <FloatingPanelPopover modal open>
+ <FloatingPanelPopoverTrigger asChild>
+ <Button>Share</Button>
+ </FloatingPanelPopoverTrigger>
+
+ <FloatingPanelPopoverContent>
+ <ShareProject
+ {...props}
+ designerUrl={({ authToken, mode }) =>
+ `https://blabla.com/${authToken}/${mode}`
+ }
+ ></ShareProject>
+ </FloatingPanelPopoverContent>
+ </FloatingPanelPopover>
);
};
export const WithLinks: ComponentStory<typeof ShareProject> = () => {
const props = useShareProject(initialLinks);
return (
- <ShareProject {...props} isOpen>
- <Button>Share</Button>
- </ShareProject>
+ <FloatingPanelPopover modal open>
+ <FloatingPanelPopoverTrigger asChild>
+ <Button>Share</Button>
+ </FloatingPanelPopoverTrigger>
+
+ <FloatingPanelPopoverContent>
+ <ShareProject
+ {...props}
+ designerUrl={({ authToken, mode }) =>
+ `https://blabla.com/${authToken}/${mode}`
+ }
+ ></ShareProject>
+ </FloatingPanelPopoverContent>
+ </FloatingPanelPopover>
+ );
+};
+
+export const WithAsyncLinks: ComponentStory<typeof ShareProject> = () => {
+ const props = useShareProject(initialLinks, true);
+ return (
+ <FloatingPanelPopover modal open>
+ <FloatingPanelPopoverTrigger asChild>
+ <Button>Share</Button>
+ </FloatingPanelPopoverTrigger>
+
+ <FloatingPanelPopoverContent>
+ <ShareProject
+ {...props}
+ designerUrl={({ authToken, mode }) =>
+ `https://blabla.com/${authToken}/${mode}`
+ }
+ ></ShareProject>
+ </FloatingPanelPopoverContent>
+ </FloatingPanelPopover>
);
};
diff --git a/apps/designer/app/shared/share-project/share-project.tsx b/apps/designer/app/shared/share-project/share-project.tsx
index b217baefb8..264c307c4f 100644
--- a/apps/designer/app/shared/share-project/share-project.tsx
+++ b/apps/designer/app/shared/share-project/share-project.tsx
@@ -1,28 +1,284 @@
-import { Button, Flex, TextField } from "@webstudio-is/design-system";
+import {
+ Box,
+ Button,
+ css,
+ Flex,
+ Label,
+ DeprecatedPopover,
+ DeprecatedPopoverContent,
+ DeprecatedPopoverTrigger,
+ rawTheme,
+ Separator,
+ Switch,
+ TextField,
+ theme,
+ Tooltip,
+ useId,
+} from "@webstudio-is/design-system";
+import { CopyIcon, InfoIcon, MenuIcon, PlusIcon } from "@webstudio-is/icons";
+import { Fragment, useState, type ComponentProps } from "react";
+import { motion } from "framer-motion";
-type ShareProjectProps = { url: string };
+const Item = (props: ComponentProps<typeof Flex>) => (
+ <Flex
+ direction="column"
+ css={{ padding: theme.spacing[7] }}
+ gap="1"
+ {...props}
+ />
+);
+
+type PermissionProps = {
+ title: string;
+ info: string;
+ checked: boolean;
+ onCheckedChange: (checked: boolean) => void;
+};
+const Permission = ({
+ title,
+ info,
+ checked,
+ onCheckedChange,
+}: PermissionProps) => {
+ const id = useId();
+
+ return (
+ <Flex align="center" gap="1">
+ <Switch checked={checked} id={id} onCheckedChange={onCheckedChange} />
+ <Label htmlFor={id}>{title}</Label>
+ <Tooltip content={info} variant="wrapped">
+ <InfoIcon color={rawTheme.colors.foregroundSubtle} tabIndex={0} />
+ </Tooltip>
+ </Flex>
+ );
+};
+
+type MenuProps = {
+ relation: Relation;
+ name: string;
+ onChangePermission: (relation: Relation) => void;
+ onChangeName: (name: string) => void;
+ onDelete: () => void;
+};
+
+const Menu = ({
+ relation,
+ name,
+ onChangePermission,
+ onChangeName,
+ onDelete,
+}: MenuProps) => {
+ const handleCheckedChange = (relation: Relation) => (checked: boolean) => {
+ if (checked) {
+ onChangePermission(relation);
+ }
+ };
+
+ return (
+ <DeprecatedPopover>
+ <DeprecatedPopoverTrigger asChild>
+ <Button
+ prefix={<MenuIcon />}
+ color="ghost"
+ aria-label="Menu Button for options"
+ ></Button>
+ </DeprecatedPopoverTrigger>
+ <DeprecatedPopoverContent>
+ <Item>
+ <Label>Name</Label>
+ <TextField
+ autoFocus
+ value={name}
+ onChange={(event) => {
+ onChangeName(event.target.value);
+ }}
+ />
+ </Item>
+ <Separator />
+ <Item>
+ <Label>Permissions</Label>
+ <Permission
+ checked={relation === "viewers"}
+ onCheckedChange={handleCheckedChange("viewers")}
+ title="View"
+ info="Recipients can only view the site"
+ />
+ {/*
+ Hide temporarily until we have a way to allow edit content but not edit tree, etc.
+
+ <Permission
+ onCheckedChange={handleCheckedChange("editors")}
+ checked={relation === "editors"}
+ title="Edit Content"
+ info="Recipients can view the site and edit content like text and images, but they will not be able to change the styles or structure of your site."
+ />
+ */}
+ <Permission
+ onCheckedChange={handleCheckedChange("builders")}
+ checked={relation === "builders"}
+ title="Build"
+ info="Recipients can view the site and edit content like text and images and change the styles or structure of your site."
+ />
+ </Item>
+ <Separator />
+ <Item>
+ {/* @todo need a menu item that looks like one from dropdown but without DropdownMenu */}
+ <Button
+ color="destructive"
+ onClick={() => {
+ onDelete();
+ }}
+ >
+ Delete Link
+ </Button>
+ </Item>
+ </DeprecatedPopoverContent>
+ </DeprecatedPopover>
+ );
+};
+
+const itemStyle = css({
+ display: "flex",
+ alignItems: "center",
+ gap: theme.spacing[3],
+ py: theme.spacing[5],
+ px: theme.spacing[9],
+ backgroundColor: theme.colors.background,
+});
+
+type Relation = "viewers" | "editors" | "builders";
+
+export type LinkOptions = {
+ token: string;
+ name: string;
+ relation: Relation;
+};
+
+type SharedLinkItemType = LinkOptions & {
+ onChangeRelation: (permission: Relation) => void;
+ onChangeName: (name: string) => void;
+ onDelete: () => void;
+ designerUrl: (props: {
+ authToken: string;
+ mode: "preview" | "edit";
+ }) => string;
+};
+
+const SharedLinkItem = ({
+ token,
+ name,
+ relation,
+ onChangeRelation,
+ onChangeName,
+ onDelete,
+ designerUrl,
+}: SharedLinkItemType) => {
+ const [currentName, setCurrentName] = useState(name);
+
+ return (
+ <Box className={itemStyle()}>
+ <Label css={{ flexGrow: 1 }}>{currentName}</Label>
+ <Button
+ prefix={<CopyIcon />}
+ onClick={() => {
+ navigator.clipboard.writeText(
+ designerUrl({
+ authToken: token,
+ mode: relation === "viewers" ? "preview" : "edit",
+ })
+ );
+ }}
+ >
+ Copy link
+ </Button>
+ <Menu
+ name={currentName}
+ relation={relation}
+ onChangePermission={onChangeRelation}
+ onChangeName={(name) => {
+ setCurrentName(name);
+ onChangeName(name);
+ }}
+ onDelete={onDelete}
+ />
+ </Box>
+ );
+};
+
+export type ShareProjectProps = {
+ links?: Array<LinkOptions>;
+ onChange: (link: LinkOptions) => void;
+ onDelete: (link: LinkOptions) => void;
+ onCreate: () => void;
+ designerUrl: SharedLinkItemType["designerUrl"];
+};
+
+const overflowHidden = css({
+ overflow: "hidden",
+});
+
+export const ShareProject = ({
+ links = [],
+ onChange,
+ onDelete,
+ onCreate,
+ designerUrl,
+}: ShareProjectProps) => {
+ const items = links.map((link) => (
+ <Fragment key={link.token}>
+ <SharedLinkItem
+ {...link}
+ onChangeRelation={(relation) => {
+ onChange({ ...link, relation });
+ }}
+ onChangeName={(name) => {
+ onChange({ ...link, name });
+ }}
+ onDelete={() => {
+ onDelete(link);
+ }}
+ designerUrl={designerUrl}
+ />
+ <Separator />
+ </Fragment>
+ ));
+
+ const create = (
+ <Box className={itemStyle({ css: { py: theme.spacing["9"] } })}>
+ <Button
+ color="neutral"
+ prefix={<PlusIcon />}
+ onClick={() => {
+ onCreate();
+ }}
+ >
+ {links.length === 0 ? "Share a custom link" : "Add another link"}
+ </Button>
+ </Box>
+ );
-export const ShareProject = ({ url }: ShareProjectProps) => {
return (
- <form
- onSubmit={(event) => {
- event.preventDefault();
- window.open(url, "_blank");
+ <Flex
+ direction="column"
+ css={{
+ width: theme.spacing[33],
}}
>
- <Flex gap="2">
- <TextField
- variant="ghost"
- readOnly
- defaultValue={url}
- onFocus={(event) => {
- event?.target.select();
+ {items.length > 0 && (
+ <motion.div
+ className={overflowHidden()}
+ initial="collapsed"
+ animate="open"
+ variants={{
+ collapsed: { opacity: 0.0, height: 0 },
+ open: { opacity: 1, height: "auto" },
}}
- />
- <Button aria-label="Open in a new tab" type="submit">
- Open
- </Button>
- </Flex>
- </form>
+ transition={{ duration: 0.15 }}
+ >
+ {items}
+ </motion.div>
+ )}
+ {create}
+ </Flex>
);
};
diff --git a/apps/designer/app/shared/share-project/share-project2.tsx b/apps/designer/app/shared/share-project/share-project2.tsx
deleted file mode 100644
index dd46c9abab..0000000000
--- a/apps/designer/app/shared/share-project/share-project2.tsx
+++ /dev/null
@@ -1,263 +0,0 @@
-import {
- Box,
- Button,
- css,
- Flex,
- Label,
- DeprecatedPopover,
- DeprecatedPopoverTrigger,
- DeprecatedPopoverContent,
- DeprecatedPopoverPortal,
- DeprecatedPopoverHeader,
- rawTheme,
- Separator,
- Switch,
- TextField,
- theme,
- Tooltip,
- useId,
-} from "@webstudio-is/design-system";
-import { CopyIcon, InfoIcon, MenuIcon, PlusIcon } from "@webstudio-is/icons";
-import { Fragment, type ComponentProps } from "react";
-
-const Item = (props: ComponentProps<typeof Flex>) => (
- <Flex
- direction="column"
- css={{ padding: theme.spacing[7] }}
- gap="1"
- {...props}
- />
-);
-
-type PermissionProps = {
- title: string;
- info: string;
- checked: boolean;
- onCheckedChange: (checked: boolean) => void;
-};
-const Permission = ({
- title,
- info,
- checked,
- onCheckedChange,
-}: PermissionProps) => {
- const id = useId();
-
- return (
- <Flex align="center" gap="1">
- <Switch checked={checked} id={id} onCheckedChange={onCheckedChange} />
- <Label htmlFor={id}>{title}</Label>
- <Tooltip content={info} variant="wrapped">
- <InfoIcon color={rawTheme.colors.foregroundSubtle} tabIndex={0} />
- </Tooltip>
- </Flex>
- );
-};
-
-type MenuProps = {
- permission: Permission;
- name: string;
- onChangePermission: (permission: Permission) => void;
- onChangeName: (name: string) => void;
- onDelete: () => void;
-};
-
-const Menu = ({
- permission,
- name,
- onChangePermission,
- onChangeName,
- onDelete,
-}: MenuProps) => {
- const handleCheckedChange =
- (permission: Permission) => (checked: boolean) => {
- if (checked) {
- onChangePermission(permission);
- }
- };
-
- return (
- <DeprecatedPopover>
- <DeprecatedPopoverTrigger asChild>
- <Button
- prefix={<MenuIcon />}
- color="ghost"
- aria-label="Menu Button for options"
- ></Button>
- </DeprecatedPopoverTrigger>
- <DeprecatedPopoverContent>
- <Item>
- <Label>Name</Label>
- <TextField
- defaultValue="Custom link"
- autoFocus
- value={name}
- onChange={(event) => {
- onChangeName(event.target.value);
- }}
- />
- </Item>
- <Separator />
- <Item>
- <Label>Permissions</Label>
- <Permission
- checked={permission === "view"}
- onCheckedChange={handleCheckedChange("view")}
- title="View"
- info="Recipients can only view the site"
- />
- <Permission
- onCheckedChange={handleCheckedChange("edit")}
- checked={permission === "edit"}
- title="Edit Content"
- info="Recipients can view the site and edit content like text and images, but they will not be able to change the styles or structure of your site."
- />
- <Permission
- onCheckedChange={handleCheckedChange("build")}
- checked={permission === "build"}
- title="Build"
- info="Recipients can view the site and edit content like text and images and change the styles or structure of your site."
- />
- </Item>
- <Separator />
- <Item>
- {/* @todo need a menu item that looks like one from dropdown but without DropdownMenu */}
- <Button
- color="destructive"
- onClick={() => {
- onDelete();
- }}
- >
- Delete Link
- </Button>
- </Item>
- </DeprecatedPopoverContent>
- </DeprecatedPopover>
- );
-};
-
-const itemStyle = css({
- display: "flex",
- alignItems: "center",
- gap: theme.spacing[3],
- py: theme.spacing[5],
- px: theme.spacing[9],
-});
-
-type Permission = "view" | "edit" | "build";
-
-export type LinkOptions = {
- url: string;
- name: string;
- permission: Permission;
-};
-
-type SharedLinkItemType = LinkOptions & {
- onChangePermission: (permission: Permission) => void;
- onChangeName: (name: string) => void;
- onDelete: () => void;
-};
-
-const SharedLinkItem = ({
- url,
- name,
- permission,
- onChangePermission,
- onChangeName,
- onDelete,
-}: SharedLinkItemType) => {
- return (
- <Box className={itemStyle()}>
- <Label css={{ flexGrow: 1 }}>{name}</Label>
- <Button
- prefix={<CopyIcon />}
- onClick={() => {
- navigator.clipboard.writeText(url);
- }}
- >
- Copy link
- </Button>
- <Menu
- name={name}
- permission={permission}
- onChangePermission={onChangePermission}
- onChangeName={onChangeName}
- onDelete={onDelete}
- />
- </Box>
- );
-};
-
-type ShareProjectProps = {
- links?: Array<LinkOptions>;
- onChange: (link: LinkOptions) => void;
- onDelete: (link: LinkOptions) => void;
- onCreate: () => void;
- children: JSX.Element;
- isOpen?: boolean;
- onOpenChange?: (isOpen: boolean) => void;
-};
-
-export const ShareProject = ({
- links = [],
- onChange,
- onDelete,
- onCreate,
- children,
- isOpen,
- onOpenChange,
-}: ShareProjectProps) => {
- const items = links.map((link) => (
- <Fragment key={link.url}>
- <SharedLinkItem
- key={link.url}
- {...link}
- onChangePermission={(permission) => {
- onChange({ ...link, permission });
- }}
- onChangeName={(name) => {
- onChange({ ...link, name });
- }}
- onDelete={() => {
- onDelete(link);
- }}
- />
- <Separator />
- </Fragment>
- ));
-
- const create = (
- <Box className={itemStyle({ css: { py: theme.spacing["9"] } })}>
- <Button
- color="neutral"
- prefix={<PlusIcon />}
- onClick={() => {
- onCreate();
- }}
- >
- {links.length === 0 ? "Share a custom link" : "Add another link"}
- </Button>
- </Box>
- );
-
- // @todo this should use FloatingPanel instead of Popover, which we need to refactor first
- return (
- <DeprecatedPopover modal open={isOpen} onOpenChange={onOpenChange}>
- <DeprecatedPopoverTrigger asChild>{children}</DeprecatedPopoverTrigger>
- <DeprecatedPopoverPortal>
- <DeprecatedPopoverContent hideArrow>
- <Flex
- direction="column"
- css={{
- width: theme.spacing[33],
- }}
- >
- {items}
- {create}
- </Flex>
- <DeprecatedPopoverHeader title="Share" />
- </DeprecatedPopoverContent>
- </DeprecatedPopoverPortal>
- </DeprecatedPopover>
- );
-};
diff --git a/apps/designer/package.json b/apps/designer/package.json
index b604071c76..99704218ef 100644
--- a/apps/designer/package.json
+++ b/apps/designer/package.json
@@ -37,6 +37,7 @@
"@trpc/server": "^10.9.0",
"@vercel/node": "^2.4.1",
"@webstudio-is/asset-uploader": "workspace:^",
+ "@webstudio-is/authorization-token": "workspace:^",
"@webstudio-is/css-data": "workspace:^",
"@webstudio-is/css-engine": "workspace:^",
"@webstudio-is/css-vars": "workspace:^",
@@ -60,6 +61,7 @@
"djb2a": "^2.0.0",
"downshift": "^6.1.7",
"fast-deep-equal": "3.1.3",
+ "framer-motion": "^6.5.1",
"hyphenate-style-name": "^1.0.4",
"immer": "^9.0.12",
"immerhin": "^0.4.0",
diff --git a/packages/authorization-token/LICENSE b/packages/authorization-token/LICENSE
new file mode 100644
index 0000000000..1f6edad9a7
--- /dev/null
+++ b/packages/authorization-token/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2022 Webstudio
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/packages/authorization-token/README.md b/packages/authorization-token/README.md
new file mode 100644
index 0000000000..1b2038b7b0
--- /dev/null
+++ b/packages/authorization-token/README.md
@@ -0,0 +1,3 @@
+# Webstudio Project
+
+Project related functionalities. This was temporarily placed here to reuse between other packages, but we need to split this into separate packages and probably remove this package entirely or keep it only for "project" specific functionality.
diff --git a/packages/authorization-token/jest.config.js b/packages/authorization-token/jest.config.js
new file mode 100644
index 0000000000..e7fc137533
--- /dev/null
+++ b/packages/authorization-token/jest.config.js
@@ -0,0 +1 @@
+export { default } from "@webstudio-is/jest-config";
diff --git a/packages/authorization-token/package.json b/packages/authorization-token/package.json
new file mode 100644
index 0000000000..b5a51308cf
--- /dev/null
+++ b/packages/authorization-token/package.json
@@ -0,0 +1,45 @@
+{
+ "name": "@webstudio-is/authorization-token",
+ "version": "0.22.0",
+ "description": "Webstudio Authorization Token",
+ "author": "Webstudio <[email protected]>",
+ "homepage": "https://webstudio.is",
+ "type": "module",
+ "scripts": {
+ "typecheck": "tsc --noEmit",
+ "test": "NODE_OPTIONS=--experimental-vm-modules jest",
+ "checks": "pnpm typecheck && pnpm lint",
+ "dev": "build-package --watch",
+ "build": "build-package",
+ "lint": "eslint ./src --ext .ts,.tsx --max-warnings 0"
+ },
+ "dependencies": {
+ "@webstudio-is/prisma-client": "workspace:^",
+ "@webstudio-is/trpc-interface": "workspace:^",
+ "zod": "^3.19.1"
+ },
+ "devDependencies": {
+ "@jest/globals": "^29.3.1",
+ "@webstudio-is/jest-config": "workspace:^",
+ "@webstudio-is/scripts": "workspace:^",
+ "@webstudio-is/tsconfig": "workspace:^",
+ "jest": "^29.3.1",
+ "typescript": "4.7.4"
+ },
+ "exports": {
+ ".": {
+ "import": "./lib/index.js",
+ "require": "./lib/cjs/index.cjs"
+ },
+ "./server": "./server.js"
+ },
+ "types": "src/index.ts",
+ "files": [
+ "lib/*",
+ "src/*",
+ "!*.test.*"
+ ],
+ "license": "MIT",
+ "private": false,
+ "sideEffects": false
+}
diff --git a/packages/authorization-token/server.d.ts b/packages/authorization-token/server.d.ts
new file mode 100644
index 0000000000..ad6dde9958
--- /dev/null
+++ b/packages/authorization-token/server.d.ts
@@ -0,0 +1 @@
+export * from "./src/index.server";
diff --git a/packages/authorization-token/server.js b/packages/authorization-token/server.js
new file mode 100644
index 0000000000..a6fbe7c12c
--- /dev/null
+++ b/packages/authorization-token/server.js
@@ -0,0 +1 @@
+export * from "./lib/index.server";
diff --git a/packages/authorization-token/src/db/authorization-token.ts b/packages/authorization-token/src/db/authorization-token.ts
new file mode 100644
index 0000000000..f90cbabfab
--- /dev/null
+++ b/packages/authorization-token/src/db/authorization-token.ts
@@ -0,0 +1,192 @@
+import {
+ prisma,
+ type AuthorizationToken,
+ type Project,
+} from "@webstudio-is/prisma-client";
+import {
+ authorizeProject,
+ authorizeAuthorizationToken,
+ type AppContext,
+} from "@webstudio-is/trpc-interface/server";
+import { v4 as uuid } from "uuid";
+
+export const findMany = async (
+ props: { projectId: Project["id"] },
+ context: AppContext
+) => {
+ // Only owner of the project can list authorization tokens
+ const canList = await authorizeProject.hasProjectPermit(
+ { projectId: props.projectId, permit: "own" },
+ context
+ );
+
+ if (canList === false) {
+ throw new Error(
+ "You don't have access to list this project authorization tokens"
+ );
+ }
+
+ // Get all leaf nodes for the project
+ const leafNodes =
+ await context.authorization.authorizeTrpc.expandLeafNodes.query({
+ namespace: "Project",
+ id: props.projectId,
+ });
+
+ const tokenLeafNodes = leafNodes.filter(
+ (leafNode) => leafNode.namespace === "Token"
+ );
+
+ const dbTokens = await prisma.authorizationToken.findMany({
+ where: {
+ token: {
+ in: tokenLeafNodes.map((leafNode) => leafNode.id),
+ },
+ },
+ // Stable order
+ orderBy: [
+ {
+ createdAt: "asc",
+ },
+ { token: "asc" },
+ ],
+ });
+
+ return dbTokens;
+};
+
+export const create = async (
+ props: {
+ projectId: Project["id"];
+ relation: AuthorizationToken["relation"];
+ name: string;
+ },
+ context: AppContext
+) => {
+ const tokenId = uuid();
+
+ // Only owner of the project can create authorization tokens
+ const canCreateToken = await authorizeProject.hasProjectPermit(
+ { projectId: props.projectId, permit: "own" },
+ context
+ );
+
+ if (canCreateToken === false) {
+ throw new Error(
+ "You don't have access to create this project authorization tokens"
+ );
+ }
+
+ await authorizeAuthorizationToken.registerToken(
+ {
+ tokenId,
+ projectId: props.projectId,
+ relation: props.relation,
+ },
+ context
+ );
+
+ const dbToken = await prisma.authorizationToken.create({
+ data: {
+ projectId: props.projectId,
+ relation: props.relation,
+ token: tokenId,
+ name: props.name,
+ },
+ });
+
+ return dbToken;
+};
+
+export const update = async (
+ props: {
+ projectId: Project["id"];
+ token: AuthorizationToken["token"];
+ name: AuthorizationToken["name"];
+ relation: AuthorizationToken["relation"];
+ },
+ context: AppContext
+) => {
+ // Only owner of the project can edit authorization tokens
+ const canCreateToken = await authorizeProject.hasProjectPermit(
+ { projectId: props.projectId, permit: "own" },
+ context
+ );
+
+ if (canCreateToken === false) {
+ throw new Error(
+ "You don't have access to edit this project authorization tokens"
+ );
+ }
+
+ const previousToken = await prisma.authorizationToken.findUnique({
+ where: {
+ // eslint-disable-next-line camelcase
+ token_projectId: {
+ projectId: props.projectId,
+ token: props.token,
+ },
+ },
+ });
+
+ if (previousToken === null) {
+ throw new Error("Authorization token not found");
+ }
+
+ if (previousToken.relation !== props.relation) {
+ await authorizeAuthorizationToken.patchToken(
+ { tokenId: props.token, projectId: props.projectId },
+ previousToken.relation,
+ props.relation,
+ context
+ );
+ }
+
+ const dbToken = await prisma.authorizationToken.update({
+ where: {
+ // eslint-disable-next-line camelcase
+ token_projectId: {
+ projectId: props.projectId,
+ token: props.token,
+ },
+ },
+ data: {
+ name: props.name,
+ relation: props.relation,
+ },
+ });
+
+ return dbToken;
+};
+
+export const remove = async (
+ props: {
+ projectId: Project["id"];
+ token: AuthorizationToken["token"];
+ },
+ context: AppContext
+) => {
+ // Only owner of the project can delete authorization tokens
+ const canDeleteToken = await authorizeProject.hasProjectPermit(
+ { projectId: props.projectId, permit: "own" },
+ context
+ );
+
+ if (canDeleteToken === false) {
+ throw new Error(
+ "You don't have access to delete this project authorization tokens"
+ );
+ }
+
+ const dbToken = await prisma.authorizationToken.delete({
+ where: {
+ // eslint-disable-next-line camelcase
+ token_projectId: {
+ projectId: props.projectId,
+ token: props.token,
+ },
+ },
+ });
+
+ return dbToken;
+};
diff --git a/packages/authorization-token/src/db/index.ts b/packages/authorization-token/src/db/index.ts
new file mode 100644
index 0000000000..97dc4fae71
--- /dev/null
+++ b/packages/authorization-token/src/db/index.ts
@@ -0,0 +1 @@
+export * as db from "./authorization-token";
diff --git a/packages/authorization-token/src/index.server.ts b/packages/authorization-token/src/index.server.ts
new file mode 100644
index 0000000000..66cfba1293
--- /dev/null
+++ b/packages/authorization-token/src/index.server.ts
@@ -0,0 +1,2 @@
+export * as db from "./db";
+export * from "./trpc";
diff --git a/packages/authorization-token/src/index.ts b/packages/authorization-token/src/index.ts
new file mode 100644
index 0000000000..61176b347e
--- /dev/null
+++ b/packages/authorization-token/src/index.ts
@@ -0,0 +1 @@
+export type { AuthorizationTokensRouter } from "./trpc";
diff --git a/packages/authorization-token/src/trpc/authorization-tokens-router.ts b/packages/authorization-token/src/trpc/authorization-tokens-router.ts
new file mode 100644
index 0000000000..76d9163019
--- /dev/null
+++ b/packages/authorization-token/src/trpc/authorization-tokens-router.ts
@@ -0,0 +1,73 @@
+import { initTRPC } from "@trpc/server";
+import type { AppContext } from "@webstudio-is/trpc-interface/server";
+import { db } from "../db";
+import { z } from "zod";
+
+const { router, procedure } = initTRPC.context<AppContext>().create();
+
+const TokenProjectRelation = z.enum(["viewers", "editors", "builders"]);
+
+export const authorizationTokenRouter = router({
+ findMany: procedure
+ .input(
+ z.object({
+ projectId: z.string(),
+ })
+ )
+ .query(async ({ input, ctx }) => {
+ return await db.findMany({ projectId: input.projectId }, ctx);
+ }),
+ create: procedure
+ .input(
+ z.object({
+ projectId: z.string(),
+ relation: TokenProjectRelation,
+ name: z.string(),
+ })
+ )
+ .mutation(async ({ input, ctx }) => {
+ return await db.create(
+ {
+ projectId: input.projectId,
+ relation: input.relation,
+ name: input.name,
+ },
+ ctx
+ );
+ }),
+ remove: procedure
+ .input(
+ z.object({
+ projectId: z.string(),
+ token: z.string(),
+ })
+ )
+ .mutation(async ({ input, ctx }) => {
+ return await db.remove(
+ { projectId: input.projectId, token: input.token },
+ ctx
+ );
+ }),
+ update: procedure
+ .input(
+ z.object({
+ projectId: z.string(),
+ token: z.string(),
+ name: z.string(),
+ relation: TokenProjectRelation,
+ })
+ )
+ .mutation(async ({ input, ctx }) => {
+ return await db.update(
+ {
+ projectId: input.projectId,
+ token: input.token,
+ name: input.name,
+ relation: input.relation,
+ },
+ ctx
+ );
+ }),
+});
+
+export type AuthorizationTokensRouter = typeof authorizationTokenRouter;
diff --git a/packages/authorization-token/src/trpc/index.ts b/packages/authorization-token/src/trpc/index.ts
new file mode 100644
index 0000000000..cd8cec4988
--- /dev/null
+++ b/packages/authorization-token/src/trpc/index.ts
@@ -0,0 +1 @@
+export * from "./authorization-tokens-router";
diff --git a/packages/authorization-token/tsconfig.json b/packages/authorization-token/tsconfig.json
new file mode 100644
index 0000000000..8b148a5ede
--- /dev/null
+++ b/packages/authorization-token/tsconfig.json
@@ -0,0 +1,7 @@
+{
+ "extends": "@webstudio-is/tsconfig/base.json",
+ "compilerOptions": {
+ "module": "ES2020",
+ "target": "ES2020"
+ }
+}
diff --git a/packages/dashboard/src/db/projects.ts b/packages/dashboard/src/db/projects.ts
index d8f6827622..16870bcc22 100644
--- a/packages/dashboard/src/db/projects.ts
+++ b/packages/dashboard/src/db/projects.ts
@@ -1,5 +1,5 @@
import { prisma } from "@webstudio-is/prisma-client";
-import { AppContext } from "@webstudio-is/trpc-interface/server";
+import type { AppContext } from "@webstudio-is/trpc-interface/server";
export const findMany = async (userId: string, context: AppContext) => {
return await prisma.dashboardProject.findMany({
diff --git a/packages/prisma-client/prisma/migrations/20230130153140_authorization-tokens-fix/migration.sql b/packages/prisma-client/prisma/migrations/20230130153140_authorization-tokens-fix/migration.sql
new file mode 100644
index 0000000000..48ddc7aa73
--- /dev/null
+++ b/packages/prisma-client/prisma/migrations/20230130153140_authorization-tokens-fix/migration.sql
@@ -0,0 +1,19 @@
+-- CreateEnum
+CREATE TYPE "AuthorizationRelation" AS ENUM ('viewers', 'editors', 'builders');
+
+-- DropTable
+DROP TABLE "AuthorizationTokens";
+
+-- DropEnum
+DROP TYPE "AuthorizationPermit";
+
+-- CreateTable
+CREATE TABLE "AuthorizationToken" (
+ "token" TEXT NOT NULL,
+ "projectId" TEXT NOT NULL,
+ "name" TEXT NOT NULL DEFAULT '',
+ "relation" "AuthorizationRelation" NOT NULL DEFAULT 'viewers',
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
+
+ CONSTRAINT "AuthorizationToken_pkey" PRIMARY KEY ("token","projectId")
+);
diff --git a/packages/prisma-client/prisma/schema.prisma b/packages/prisma-client/prisma/schema.prisma
index d55f11e6b2..958b1a3d12 100644
--- a/packages/prisma-client/prisma/schema.prisma
+++ b/packages/prisma-client/prisma/schema.prisma
@@ -82,16 +82,16 @@ model Build {
}
model Tree {
- id String @id @default(uuid())
+ id String @id @default(uuid())
project Project @relation(fields: [projectId], references: [id])
projectId String
- build Build @relation(fields: [buildId], references: [id])
+ build Build @relation(fields: [buildId], references: [id])
buildId String
root String
- instances String @default("[]")
- props String @default("[]")
- styles String @default("[]")
- styleSelections String @default("[]")
+ instances String @default("[]")
+ props String @default("[]")
+ styles String @default("[]")
+ styleSelections String @default("[]")
}
model Breakpoints {
@@ -100,18 +100,21 @@ model Breakpoints {
values String @default("[]")
}
-enum AuthorizationPermit {
- VIEW
- EDIT
+enum AuthorizationRelation {
+ viewers
+ editors
+ builders
}
-model AuthorizationTokens {
- id String @id @default(uuid())
+model AuthorizationToken {
+ token String @default(uuid())
// No relation to Project, as the Authorization system is not tied to a project
projectId String
- token String
- permit AuthorizationPermit
- createdAt DateTime @default(now())
+ name String @default("")
+ relation AuthorizationRelation @default(viewers)
+ createdAt DateTime @default(now())
+
+ @@id([token, projectId])
}
// Dashboard
diff --git a/packages/prisma-client/src/types.ts b/packages/prisma-client/src/types.ts
index 5e75445f8d..b564664793 100644
--- a/packages/prisma-client/src/types.ts
+++ b/packages/prisma-client/src/types.ts
@@ -7,4 +7,5 @@ export type {
Asset,
Tree,
DashboardProject,
+ AuthorizationToken,
} from "@prisma/client";
diff --git a/packages/project/src/db/project.ts b/packages/project/src/db/project.ts
index a9af6ed32c..281f3d633b 100644
--- a/packages/project/src/db/project.ts
+++ b/packages/project/src/db/project.ts
@@ -107,7 +107,7 @@ export const create = async (
}
const projectId = uuid();
- authorizeProject.registerProjectOwnerAndReadToken({ projectId }, context);
+ authorizeProject.registerProjectOwner({ projectId }, context);
const project = await prisma.$transaction(async (client) => {
const project = await client.project.create({
@@ -201,7 +201,7 @@ const clone = async (
: await db.build.loadByProjectId(project.id, "prod");
const projectId = uuid();
- authorizeProject.registerProjectOwnerAndReadToken({ projectId }, context);
+ authorizeProject.registerProjectOwner({ projectId }, context);
const clonedProject = await prisma.$transaction(async (client) => {
const clonedProject = await client.project.create({
diff --git a/packages/trpc-interface/src/authorize/authorization-token.server.ts b/packages/trpc-interface/src/authorize/authorization-token.server.ts
new file mode 100644
index 0000000000..71cb4248e2
--- /dev/null
+++ b/packages/trpc-interface/src/authorize/authorization-token.server.ts
@@ -0,0 +1,106 @@
+import type { AppContext } from "../context/context.server";
+
+/**
+ * For 3rd party authorization systems like Ory we need to register token for the project.
+ *
+ * We do that before the authorizationToken create (and out of the transaction),
+ * so in case of an error we will have just stale records of non existed projects in authorization system.
+ */
+export const registerToken = async (
+ props: {
+ projectId: string;
+ tokenId: string;
+ relation: "viewers" | "editors" | "builders";
+ },
+ context: AppContext
+) => {
+ const { authorization } = context;
+ const { userId, authorizeTrpc } = authorization;
+
+ if (userId === undefined) {
+ throw new Error("The user must be authenticated to create a token");
+ }
+
+ await authorizeTrpc.create.mutate({
+ namespace: "Project",
+ id: props.projectId,
+ relation: props.relation,
+ subjectSet: {
+ namespace: "Token",
+ id: props.tokenId,
+ },
+ });
+};
+
+// Implement any update operations in the single transaction on authorization system
+export const patchToken = async (
+ props: { projectId: string; tokenId: string },
+
+ prevRelation: "viewers" | "editors" | "builders",
+
+ nextRelation: "viewers" | "editors" | "builders",
+
+ context: AppContext
+) => {
+ const { authorization } = context;
+ const { userId, authorizeTrpc } = authorization;
+
+ if (userId === undefined) {
+ throw new Error("The user must be authenticated to delete a token");
+ }
+
+ if (prevRelation !== nextRelation) {
+ await authorizeTrpc.patch.mutate([
+ {
+ action: "delete",
+ relationTuple: {
+ namespace: "Project",
+ id: props.projectId,
+ relation: prevRelation,
+ subjectSet: {
+ namespace: "Token",
+ id: props.tokenId,
+ },
+ },
+ },
+ {
+ action: "insert",
+ relationTuple: {
+ namespace: "Project",
+ id: props.projectId,
+ relation: nextRelation,
+ subjectSet: {
+ namespace: "Token",
+ id: props.tokenId,
+ },
+ },
+ },
+ ]);
+ }
+};
+
+export const unregisterToken = async (
+ props: {
+ projectId: string;
+ tokenId: string;
+ relation: "viewers" | "editors";
+ },
+ context: AppContext
+) => {
+ const { authorization } = context;
+ const { userId, authorizeTrpc } = authorization;
+
+ if (userId === undefined) {
+ throw new Error("The user must be authenticated to delete a token");
+ }
+
+ await authorizeTrpc.delete.mutate({
+ namespace: "Project",
+ id: props.projectId,
+ relation: props.relation,
+ subjectSet: {
+ namespace: "Token",
+ id: props.tokenId,
+ },
+ });
+};
diff --git a/packages/trpc-interface/src/authorize/project.server.ts b/packages/trpc-interface/src/authorize/project.server.ts
index e694857401..e3340e4994 100644
--- a/packages/trpc-interface/src/authorize/project.server.ts
+++ b/packages/trpc-interface/src/authorize/project.server.ts
@@ -1,14 +1,12 @@
-import { AppContext } from "../context/context.server";
-import { v4 as uuid } from "uuid";
+import type { AppContext } from "../context/context.server";
/**
- * For 3rd party authorization systems like Ory we need to register the project owner
- * and create an initial read token for the project.
+ * For 3rd party authorization systems like Ory we need to register the project owner.
*
* We do that before the project create (and out of the transaction),
* so in case of an error we will have just stale records of non existed projects in authorization system.
*/
-export const registerProjectOwnerAndReadToken = async (
+export const registerProjectOwner = async (
props: { projectId: string },
context: AppContext
) => {
@@ -22,22 +20,12 @@ export const registerProjectOwnerAndReadToken = async (
await authorizeTrpc.create.mutate({
namespace: "Project",
id: props.projectId,
- relation: "owner",
+ relation: "owners",
subjectSet: {
namespace: "User",
id: userId,
},
});
-
- await authorizeTrpc.create.mutate({
- namespace: "Project",
- id: props.projectId,
- relation: "viewers",
- subjectSet: {
- namespace: "Token",
- id: uuid(),
- },
- });
};
export const hasProjectPermit = async (
@@ -83,7 +71,8 @@ export const hasProjectPermit = async (
}
// Check if the special link with a token allows to access the project
- if (authorization.authToken !== undefined) {
+ // Token doesn't have own permit, do not check it
+ if (authorization.authToken !== undefined && props.permit !== "own") {
checks.push(
authorizeTrpc.check.query({
namespace,
diff --git a/packages/trpc-interface/src/context/context.server.ts b/packages/trpc-interface/src/context/context.server.ts
index 6c73552618..ac70fe98e3 100644
--- a/packages/trpc-interface/src/context/context.server.ts
+++ b/packages/trpc-interface/src/context/context.server.ts
@@ -22,7 +22,7 @@ type AuthorizationContext = {
authToken: string | undefined;
/**
- * buildEnv see prisma Build isDev isProd, we always allow to load production build/project
+ * buildEnv==="prod" only if we are loading project with production build
*/
buildEnv: "dev" | "prod";
diff --git a/packages/trpc-interface/src/index.server.ts b/packages/trpc-interface/src/index.server.ts
index 2f261d4e8f..8da2650aef 100644
--- a/packages/trpc-interface/src/index.server.ts
+++ b/packages/trpc-interface/src/index.server.ts
@@ -3,3 +3,4 @@ export { createTrpcProxyServiceClient } from "./shared/client";
export type { AppContext } from "./context/context.server";
export * as authorizeProject from "./authorize/project.server";
+export * as authorizeAuthorizationToken from "./authorize/authorization-token.server";
diff --git a/packages/trpc-interface/src/shared/authorization-router.ts b/packages/trpc-interface/src/shared/authorization-router.ts
index 0c5d2b99dd..57af416f05 100644
--- a/packages/trpc-interface/src/shared/authorization-router.ts
+++ b/packages/trpc-interface/src/shared/authorization-router.ts
@@ -3,6 +3,42 @@ import { router, procedure } from "./trpc";
import { prisma } from "@webstudio-is/prisma-client";
+const Relation = z.enum(["viewers", "editors", "builders", "owners"]);
+
+const DeleteCreateInput = z.discriminatedUnion("namespace", [
+ z.object({
+ namespace: z.literal("Project"),
+ id: z.string(),
+ relation: Relation,
+
+ subjectSet: z.discriminatedUnion("namespace", [
+ z.object({
+ namespace: z.literal("User"),
+ id: z.string(),
+ }),
+ z.object({
+ namespace: z.literal("Token"),
+ id: z.string(),
+ }),
+ z.object({
+ namespace: z.literal("Email"),
+ id: z.string(),
+ relation: z.literal("owners"),
+ }),
+ ]),
+ }),
+
+ z.object({
+ namespace: z.literal("Email"),
+ id: z.string(),
+ relation: z.enum(["owners"]),
+ subjectSet: z.object({
+ namespace: z.literal("User"),
+ id: z.string(),
+ }),
+ }),
+]);
+
export const authorizationRouter = router({
/**
* Relation expansion in authorize looks like a tree
@@ -26,7 +62,7 @@ export const authorizationRouter = router({
z.array(
z.object({
// top level relation
- relation: z.enum(["owner", "editors", "viewers"]),
+ relation: Relation,
// subjectSet
namespace: z.enum(["Email", "User", "Token"]),
id: z.string(),
@@ -50,7 +86,7 @@ export const authorizationRouter = router({
},
});
- const tokenRows = await prisma.authorizationTokens.findMany({
+ const tokenRows = await prisma.authorizationToken.findMany({
where: {
projectId: id,
},
@@ -62,7 +98,7 @@ export const authorizationRouter = router({
leafSubjectSets.push({
namespace: "User",
id: ownerRow.userId,
- relation: "owner",
+ relation: "owners",
} as const);
}
@@ -70,7 +106,7 @@ export const authorizationRouter = router({
leafSubjectSets.push({
namespace: "Token",
id: tokenRow.token,
- relation: tokenRow.permit === "EDIT" ? "editors" : "viewers",
+ relation: tokenRow.relation,
} as const);
}
@@ -86,7 +122,7 @@ export const authorizationRouter = router({
namespace: z.enum(["Project"]),
id: z.string(),
- permit: z.enum(["view", "edit", "own"]),
+ permit: z.enum(["view", "edit", "build", "own"]),
subjectSet: z.object({
namespace: z.enum(["User", "Token"]),
@@ -113,16 +149,21 @@ export const authorizationRouter = router({
return { allowed: row !== null };
}
+ const permitToRelationRewrite = {
+ view: ["viewers", "editors", "builders"],
+ edit: ["editors", "builders"],
+ build: ["builders"],
+ } as const;
+
if (subjectSet.namespace === "Token" && input.permit !== "own") {
- const row = await prisma.authorizationTokens.findFirst({
+ const row = await prisma.authorizationToken.findFirst({
where: {
token: subjectSet.id,
- permit: {
- // Token with EDIT permit can also VIEW
- in: input.permit === "view" ? ["VIEW", "EDIT"] : ["VIEW"],
+ relation: {
+ in: [...permitToRelationRewrite[input.permit]],
},
},
- select: { id: true },
+ select: { token: true },
});
return { allowed: row !== null };
@@ -131,115 +172,25 @@ export const authorizationRouter = router({
return { allowed: false };
}),
/**
- * In OSS we extract owner relation from the Project table, and the rest from the authorizationTokens table
+ * In OSS we extract owner relation from the Project table, and the rest from the authorizationToken table
*/
- create: procedure
- .input(
- z.discriminatedUnion("namespace", [
- z.object({
- namespace: z.literal("Project"),
- id: z.string(),
- relation: z.enum(["viewers", "editors", "owner"]),
-
- subjectSet: z.discriminatedUnion("namespace", [
- z.object({
- namespace: z.literal("User"),
- id: z.string(),
- }),
- z.object({
- namespace: z.literal("Token"),
- id: z.string(),
- }),
- z.object({
- namespace: z.literal("Email"),
- id: z.string(),
- relation: z.literal("owner"),
- }),
- ]),
- }),
-
- z.object({
- namespace: z.literal("Email"),
- id: z.string(),
- relation: z.enum(["owner"]),
- subjectSet: z.object({
- namespace: z.literal("User"),
- id: z.string(),
- }),
- }),
- ])
- )
- .mutation(async ({ input }) => {
- const { namespace, id, relation, subjectSet } = input;
- if (namespace === "Project") {
- if (subjectSet.namespace === "Token") {
- if (relation === "owner") {
- throw new Error("Token relation owner is prohibited");
- }
-
- await prisma.authorizationTokens.create({
- data: {
- projectId: id,
- token: subjectSet.id,
- permit: relation === "viewers" ? "VIEW" : "EDIT",
- },
- });
- }
- }
- }),
-
- delete: procedure
+ create: procedure.input(DeleteCreateInput).mutation(async ({ input }) => {
+ // Do nothing in OSS
+ }),
+
+ delete: procedure.input(DeleteCreateInput).mutation(async ({ input }) => {
+ // Do nothing in OSS
+ }),
+ patch: procedure
.input(
- z.discriminatedUnion("namespace", [
- z.object({
- namespace: z.literal("Project"),
- id: z.string(),
- relation: z.enum(["viewers", "editors", "owner"]),
-
- subjectSet: z.discriminatedUnion("namespace", [
- z.object({
- namespace: z.literal("User"),
- id: z.string(),
- }),
- z.object({
- namespace: z.literal("Token"),
- id: z.string(),
- }),
- z.object({
- namespace: z.literal("Email"),
- id: z.string(),
- relation: z.literal("owner"),
- }),
- ]),
- }),
-
+ z.array(
z.object({
- namespace: z.literal("Email"),
- id: z.string(),
- relation: z.enum(["owner"]),
- subjectSet: z.object({
- namespace: z.literal("User"),
- id: z.string(),
- }),
- }),
- ])
+ action: z.enum(["insert", "delete"]),
+ relationTuple: DeleteCreateInput,
+ })
+ )
)
.mutation(async ({ input }) => {
- const { namespace, id, relation, subjectSet } = input;
- if (namespace === "Project") {
- if (subjectSet.namespace === "Token") {
- if (relation === "owner") {
- throw new Error("Token relation owner is prohibited");
- }
-
- await prisma.authorizationTokens.deleteMany({
- where: {
- projectId: id,
- token: subjectSet.id,
- permit: relation === "viewers" ? "VIEW" : "EDIT",
- },
- });
- }
- }
+ // Do nothing in OSS
}),
});
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 510640bf0d..59a03278af 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -85,6 +85,7 @@ importers:
'@types/w3c-css-typed-object-model-level-1': ^20180410.0.4
'@vercel/node': ^2.4.1
'@webstudio-is/asset-uploader': workspace:^
+ '@webstudio-is/authorization-token': workspace:^
'@webstudio-is/css-data': workspace:^
'@webstudio-is/css-engine': workspace:^
'@webstudio-is/css-vars': workspace:^
@@ -115,6 +116,7 @@ importers:
downshift: ^6.1.7
esbuild-node-externals: ^1.4.1
fast-deep-equal: 3.1.3
+ framer-motion: ^6.5.1
hyphenate-style-name: ^1.0.4
immer: ^9.0.12
immerhin: ^0.4.0
@@ -175,6 +177,7 @@ importers:
'@trpc/server': 10.9.0
'@vercel/node': 2.4.1
'@webstudio-is/asset-uploader': link:../../packages/asset-uploader
+ '@webstudio-is/authorization-token': link:../../packages/authorization-token
'@webstudio-is/css-data': link:../../packages/css-data
'@webstudio-is/css-engine': link:../../packages/css-engine
'@webstudio-is/css-vars': link:../../packages/css-vars
@@ -198,6 +201,7 @@ importers:
djb2a: 2.0.0
downshift: [email protected]
fast-deep-equal: 3.1.3
+ framer-motion: 6.5.1_sfoxds7t5ydpegc3knd667wn6m
hyphenate-style-name: 1.0.4
immer: 9.0.15
immerhin: 0.4.0
@@ -312,6 +316,29 @@ importers:
typescript: 4.7.4
zod: 3.19.1
+ packages/authorization-token:
+ specifiers:
+ '@jest/globals': ^29.3.1
+ '@webstudio-is/jest-config': workspace:^
+ '@webstudio-is/prisma-client': workspace:^
+ '@webstudio-is/scripts': workspace:^
+ '@webstudio-is/trpc-interface': workspace:^
+ '@webstudio-is/tsconfig': workspace:^
+ jest: ^29.3.1
+ typescript: 4.7.4
+ zod: ^3.19.1
+ dependencies:
+ '@webstudio-is/prisma-client': link:../prisma-client
+ '@webstudio-is/trpc-interface': link:../trpc-interface
+ zod: 3.19.1
+ devDependencies:
+ '@jest/globals': 29.3.1
+ '@webstudio-is/jest-config': link:../jest-config
+ '@webstudio-is/scripts': link:../scripts
+ '@webstudio-is/tsconfig': link:../tsconfig
+ jest: 29.3.1
+ typescript: 4.7.4
+
packages/css-data:
specifiers:
'@types/css-tree': ^2.0.0
@@ -5338,6 +5365,19 @@ packages:
resolution: {integrity: sha512-14FtKiHhy2QoPIzdTcvh//8OyBlknNs2nXRwIhG904opCby3l+9Xaf/wuPvICBF0rc1ZCNBd3nKe9cd2mecVkQ==}
dev: true
+ /@emotion/is-prop-valid/0.8.8:
+ resolution: {integrity: sha512-u5WtneEAr5IDG2Wv65yhunPSMLIpuKsbuOktRojfrEiEvRyC85LgPMZI63cr7NUqT8ZIGdSVg8ZKGxIug4lXcA==}
+ requiresBuild: true
+ dependencies:
+ '@emotion/memoize': 0.7.4
+ dev: false
+ optional: true
+
+ /@emotion/memoize/0.7.4:
+ resolution: {integrity: sha512-Ja/Vfqe3HpuzRsG1oBtWTHk2PGZ7GR+2Vz5iYGelAw8dx32K0y7PjVuxK6z1nMpZOqAFsRUPCkK1YjJ56qJlgw==}
+ dev: false
+ optional: true
+
/@esbuild-kit/cjs-loader/2.4.1:
resolution: {integrity: sha512-lhc/XLith28QdW0HpHZvZKkorWgmCNT7sVelMHDj3HFdTfdqkwEKvT+aXVQtNAmCC39VJhunDkWhONWB7335mg==}
dependencies:
@@ -6082,6 +6122,53 @@ packages:
/@mdx-js/util/1.6.22:
resolution: {integrity: sha512-H1rQc1ZOHANWBvPcW+JpGwr+juXSxM8Q8YCkm3GhZd8REu1fHR3z99CErO1p9pkcfcxZnMdIZdIsXkOHY0NilA==}
+ /@motionone/animation/10.15.1:
+ resolution: {integrity: sha512-mZcJxLjHor+bhcPuIFErMDNyrdb2vJur8lSfMCsuCB4UyV8ILZLvK+t+pg56erv8ud9xQGK/1OGPt10agPrCyQ==}
+ dependencies:
+ '@motionone/easing': 10.15.1
+ '@motionone/types': 10.15.1
+ '@motionone/utils': 10.15.1
+ tslib: 2.5.0
+ dev: false
+
+ /@motionone/dom/10.12.0:
+ resolution: {integrity: sha512-UdPTtLMAktHiqV0atOczNYyDd/d8Cf5fFsd1tua03PqTwwCe/6lwhLSQ8a7TbnQ5SN0gm44N1slBfj+ORIhrqw==}
+ dependencies:
+ '@motionone/animation': 10.15.1
+ '@motionone/generators': 10.15.1
+ '@motionone/types': 10.15.1
+ '@motionone/utils': 10.15.1
+ hey-listen: 1.0.8
+ tslib: 2.5.0
+ dev: false
+
+ /@motionone/easing/10.15.1:
+ resolution: {integrity: sha512-6hIHBSV+ZVehf9dcKZLT7p5PEKHGhDwky2k8RKkmOvUoYP3S+dXsKupyZpqx5apjd9f+php4vXk4LuS+ADsrWw==}
+ dependencies:
+ '@motionone/utils': 10.15.1
+ tslib: 2.5.0
+ dev: false
+
+ /@motionone/generators/10.15.1:
+ resolution: {integrity: sha512-67HLsvHJbw6cIbLA/o+gsm7h+6D4Sn7AUrB/GPxvujse1cGZ38F5H7DzoH7PhX+sjvtDnt2IhFYF2Zp1QTMKWQ==}
+ dependencies:
+ '@motionone/types': 10.15.1
+ '@motionone/utils': 10.15.1
+ tslib: 2.5.0
+ dev: false
+
+ /@motionone/types/10.15.1:
+ resolution: {integrity: sha512-iIUd/EgUsRZGrvW0jqdst8st7zKTzS9EsKkP+6c6n4MPZoQHwiHuVtTQLD6Kp0bsBLhNzKIBlHXponn/SDT4hA==}
+ dev: false
+
+ /@motionone/utils/10.15.1:
+ resolution: {integrity: sha512-p0YncgU+iklvYr/Dq4NobTRdAPv9PveRDUXabPEeOjBLSO/1FNB2phNTZxOxpi1/GZwYpAoECEa0Wam+nsmhSw==}
+ dependencies:
+ '@motionone/types': 10.15.1
+ hey-listen: 1.0.8
+ tslib: 2.5.0
+ dev: false
+
/@mrmlnc/readdir-enhanced/2.2.1:
resolution: {integrity: sha512-bPHp6Ji8b41szTOcaP63VlnbbO5Ny6dwAATtY6JTjh5N2OLrb5Qk/Th5cRkRQhkWCt+EJsYrNB0MiL+Gpn6e3g==}
engines: {node: '>=4'}
@@ -9770,7 +9857,7 @@ packages:
flat-cache: 3.0.4
micromatch: 4.0.5
react-docgen-typescript: [email protected]
- tslib: 2.4.0
+ tslib: 2.5.0
typescript: 4.7.4
webpack: 5.75.0
transitivePeerDependencies:
@@ -12074,7 +12161,7 @@ packages:
resolution: {integrity: sha512-O0yuUDnZeQDL+ncNGlJ78BiO4jnYI3bvMsD5prT0/nsgijG/LpNBIr63gTjVTNsiGkgQhiyCShTgxt8oXOrklA==}
engines: {node: '>=4'}
dependencies:
- tslib: 2.4.0
+ tslib: 2.5.0
dev: true
/ast-types/0.15.2:
@@ -12877,7 +12964,7 @@ packages:
resolution: {integrity: sha512-gxGWBrTT1JuMx6R+o5PTXMmUnhnVzLQ9SNutD4YqKtI6ap897t3tKECYla6gCWEkplXnlNybEkZg9GEGxKFCgw==}
dependencies:
pascal-case: 3.1.2
- tslib: 2.4.0
+ tslib: 2.5.0
/camelcase-css/2.0.1:
resolution: {integrity: sha512-QOSvevhslijgYwRx6Rv7zKdMF8lbRmx+uQGx2+vDc+KI/eBnsy9kit5aj23AgGu3pa4t9AgwbnXWqS+iOY+2aA==}
@@ -14030,7 +14117,7 @@ packages:
resolution: {integrity: sha512-Kv5nKlh6yRrdrGvxeJ2e5y2eRUpkUosIW4A2AS38zwSz27zu7ufDwQPi5Jhs3XAlGNetl3bmnGhQsMtkKJnj3w==}
dependencies:
no-case: 3.0.4
- tslib: 2.4.0
+ tslib: 2.5.0
/dotenv-expand/5.1.0:
resolution: {integrity: sha512-YXQl1DSa4/PQyRfgrv6aoNjhasp/p4qs9FjJ4q4cQk+8m4r6k4ZSiEyytKG8f8W9gi8WsQtIObNmKd+tMzNTmA==}
@@ -15456,6 +15543,30 @@ packages:
dependencies:
map-cache: 0.2.2
+ /framer-motion/6.5.1_sfoxds7t5ydpegc3knd667wn6m:
+ resolution: {integrity: sha512-o1BGqqposwi7cgDrtg0dNONhkmPsUFDaLcKXigzuTFC5x58mE8iyTazxSudFzmT6MEyJKfjjU8ItoMe3W+3fiw==}
+ peerDependencies:
+ react: '>=16.8 || ^17.0.0 || ^18.0.0'
+ react-dom: '>=16.8 || ^17.0.0 || ^18.0.0'
+ dependencies:
+ '@motionone/dom': 10.12.0
+ framesync: 6.0.1
+ hey-listen: 1.0.8
+ popmotion: 11.0.3
+ react: 17.0.2
+ react-dom: [email protected]
+ style-value-types: 5.0.0
+ tslib: 2.5.0
+ optionalDependencies:
+ '@emotion/is-prop-valid': 0.8.8
+ dev: false
+
+ /framesync/6.0.1:
+ resolution: {integrity: sha512-fUY88kXvGiIItgNC7wcTOl0SNRCVXMKSWW2Yzfmn7EKNc+MpCzcz9DhdHcdjbrtN3c6R4H5dTY2jiCpPdysEjA==}
+ dependencies:
+ tslib: 2.5.0
+ dev: false
+
/fresh/0.5.2:
resolution: {integrity: sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q==}
engines: {node: '>= 0.6'}
@@ -16065,6 +16176,10 @@ packages:
resolution: {integrity: sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==}
hasBin: true
+ /hey-listen/1.0.8:
+ resolution: {integrity: sha512-COpmrF2NOg4TBWUJ5UVyaCU2A88wEMkUPK4hNqyCkqHbxT92BbvfjoSozkAIIm6XhicGlJHhFdullInrdhwU8Q==}
+ dev: false
+
/hmac-drbg/1.0.1:
resolution: {integrity: sha512-Tti3gMqLdZfhOQY1Mzf/AanLiqh1WTiJgEj26ZuYQ9fbkLomzGchCws4FyrSd4VkpBfiNhaE1On+lOz894jvXg==}
dependencies:
@@ -17781,7 +17896,7 @@ packages:
/lower-case/2.0.2:
resolution: {integrity: sha512-7fm3l3NAF9WfN6W3JOmf5drwpVqX78JtoGJ3A6W0a6ZnldM41w2fV5D490psKFTpMds8TJse/eHLFFsNHHjHgg==}
dependencies:
- tslib: 2.4.0
+ tslib: 2.5.0
/lowercase-keys/2.0.0:
resolution: {integrity: sha512-tqNXrS78oMOE73NMxK4EMLQsQowWf8jKooH9g7xPavRT706R6bkQJ6DY2Te7QukaZsulxa30wQ7bk0pm4XiHmA==}
@@ -18733,7 +18848,7 @@ packages:
resolution: {integrity: sha512-fgAN3jGAh+RoxUGZHTSOLJIqUc2wmoBwGR4tbpNAKmmovFoWq0OdRkb0VkldReO2a2iBT/OEulG9XSUc10r3zg==}
dependencies:
lower-case: 2.0.2
- tslib: 2.4.0
+ tslib: 2.5.0
/node-abi/3.22.0:
resolution: {integrity: sha512-u4uAs/4Zzmp/jjsD9cyFYDXeISfUWaAVWshPmDZOFOv4Xl4SbzTXm53I04C2uRueYJ+0t5PEtLH/owbn2Npf/w==}
@@ -19248,7 +19363,7 @@ packages:
resolution: {integrity: sha512-RXlj7zCYokReqWpOPH9oYivUzLYZ5vAPIfEmCTNViosC78F8F0H9y7T7gG2M39ymgutxF5gcFEsyZQSph9Bp3A==}
dependencies:
dot-case: 3.0.4
- tslib: 2.4.0
+ tslib: 2.5.0
/parent-module/1.0.1:
resolution: {integrity: sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g==}
@@ -19320,7 +19435,7 @@ packages:
resolution: {integrity: sha512-uWlGT3YSnK9x3BQJaOdcZwrnV6hPpd8jFH1/ucpiLRPh/2zCVJKS19E4GvYHvaCcACn3foXZ0cLB9Wrx1KGe5g==}
dependencies:
no-case: 3.0.4
- tslib: 2.4.0
+ tslib: 2.5.0
/pascalcase/0.1.1:
resolution: {integrity: sha512-XHXfu/yOQRy9vYOtUDVMN60OEJjW013GoObG1o+xwQTpB9eYJX/BjXMsdW13ZDPruFhYYn0AG22w0xgQMwl3Nw==}
@@ -19509,6 +19624,15 @@ packages:
engines: {node: '>=12.0.0'}
dev: false
+ /popmotion/11.0.3:
+ resolution: {integrity: sha512-Y55FLdj3UxkR7Vl3s7Qr4e9m0onSnP8W7d/xQLsoJM40vs6UKHFdygs6SWryasTZYqugMjm3BepCF4CWXDiHgA==}
+ dependencies:
+ framesync: 6.0.1
+ hey-listen: 1.0.8
+ style-value-types: 5.0.0
+ tslib: 2.5.0
+ dev: false
+
/posix-character-classes/0.1.1:
resolution: {integrity: sha512-xTgYBc3fuo7Yt7JbiuFxSYGToMoz8fLoE6TC9Wx1P/u+LfeThMOAqmuyECnlBaaJb+u1m9hHiXUEtwW4OzfUJg==}
engines: {node: '>=0.10.0'}
@@ -20210,7 +20334,7 @@ packages:
'@types/react': 17.0.47
react: 17.0.2
react-style-singleton: 2.2.1_sudpmbbyhqtxq6t4xf6jlicdem
- tslib: 2.4.0
+ tslib: 2.5.0
dev: false
/react-remove-scroll/2.5.4_sudpmbbyhqtxq6t4xf6jlicdem:
@@ -20277,7 +20401,7 @@ packages:
get-nonce: 1.0.1
invariant: 2.2.4
react: 17.0.2
- tslib: 2.4.0
+ tslib: 2.5.0
dev: false
/react-test-renderer/[email protected]:
@@ -21780,6 +21904,13 @@ packages:
inline-style-parser: 0.1.1
dev: true
+ /style-value-types/5.0.0:
+ resolution: {integrity: sha512-08yq36Ikn4kx4YU6RD7jWEv27v4V+PUsOGa4n/as8Et3CuODMJQ00ENeAVXAeydX4Z2j1XHZF1K2sX4mGl18fA==}
+ dependencies:
+ hey-listen: 1.0.8
+ tslib: 2.5.0
+ dev: false
+
/stylis/4.1.1:
resolution: {integrity: sha512-lVrM/bNdhVX2OgBFNa2YJ9Lxj7kPzylieHd3TNjuGE0Re9JB7joL5VUKOVH1kdNNJTgGPpT8hmwIAPLaSyEVFQ==}
dev: false
@@ -22211,10 +22342,10 @@ packages:
/tslib/2.4.0:
resolution: {integrity: sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ==}
+ dev: false
/tslib/2.5.0:
resolution: {integrity: sha512-336iVw3rtn2BUK7ORdIAHTyxHGRIHVReokCR3XjbckJMK7ms8FysBfhLR8IXnAgy7T0PTPNBWKiH514FOW/WSg==}
- dev: true
resolution: {integrity: sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==}
@@ -22689,7 +22820,7 @@ packages:
dependencies:
'@types/react': 17.0.47
react: 17.0.2
- tslib: 2.4.0
+ tslib: 2.5.0
dev: false
/use-debounce/[email protected]:
@@ -22727,7 +22858,7 @@ packages:
'@types/react': 17.0.47
detect-node-es: 1.1.0
react: 17.0.2
- tslib: 2.4.0
+ tslib: 2.5.0
dev: false
/use-sync-external-store/[email protected]: