Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

Do API calls in desktop frontend via ts-rest (#201)

Brendan Allan65e8054a9c71
diff --git a/.github/actions/setup-js/action.yml b/.github/actions/setup-js/action.yml
index a3733106e..4f0bf81c4 100644
--- a/.github/actions/setup-js/action.yml
+++ b/.github/actions/setup-js/action.yml
@@ -12,7 +12,7 @@ runs:
- name: Setup node
uses: actions/setup-node@v3
with:
- node-version: 18
+ node-version: 20
cache: pnpm
- name: Install frontend dependencies
diff --git a/apps/desktop/package.json b/apps/desktop/package.json
index c45e34fad..67168006c 100644
--- a/apps/desktop/package.json
+++ b/apps/desktop/package.json
@@ -12,6 +12,7 @@
"@cap/ui": "workspace:*",
"@cap/ui-solid": "workspace:*",
"@cap/utils": "workspace:*",
+ "@cap/web-api-contract": "workspace:*",
"@corvu/tooltip": "^0.2.1",
"@kobalte/core": "^0.13.7",
"@solid-primitives/bounds": "^0.0.122",
@@ -41,6 +42,7 @@
"@tauri-apps/plugin-shell": ">=2.0.0-rc.0",
"@tauri-apps/plugin-store": "2.1.0",
"@tauri-apps/plugin-updater": "2.0.0-rc.0",
+ "@ts-rest/core": "^3.51.0",
"@types/react-tooltip": "^4.2.4",
"cva": "npm:class-variance-authority@^0.7.0",
"effect": "^3.7.2",
diff --git a/apps/desktop/src/routes/(window-chrome)/(main).tsx b/apps/desktop/src/routes/(window-chrome)/(main).tsx
index 5a1212957..1750a0ed5 100644
--- a/apps/desktop/src/routes/(window-chrome)/(main).tsx
+++ b/apps/desktop/src/routes/(window-chrome)/(main).tsx
@@ -50,11 +50,17 @@ import {
const getAuth = cache(async () => {
const value = await authStore.get();
const local = import.meta.env.VITE_LOCAL_MODE === "true";
- if (!value && !local) return redirect("/signin");
- const res = await fetch(`${clientEnv.VITE_SERVER_URL}/api/desktop/plan`, {
- headers: { authorization: `Bearer ${value?.token}` },
+
+ if (!value) {
+ if (local) return;
+ return redirect("/signin");
+ }
+
+ const res = await apiClient.getUserPlan({
+ headers: await protectedHeaders(),
});
if (res.status !== 200 && !local) return redirect("/signin");
+
return value;
}, "getAuth");
@@ -258,6 +264,7 @@ import * as updater from "@tauri-apps/plugin-updater";
import { makePersisted } from "@solid-primitives/storage";
import titlebarState, { setTitlebar } from "~/utils/titlebar-state";
import { type as ostype } from "@tauri-apps/plugin-os";
+import { apiClient, protectedHeaders } from "~/utils/web-api";
let hasChecked = false;
function createUpdateCheck() {
@@ -767,10 +774,11 @@ function ChangelogButton() {
if (!version) {
return { hasUpdate: false };
}
- const response = await fetch(
- `${clientEnv.VITE_SERVER_URL}/api/changelog/status?version=${version}`
- );
- return await response.json();
+ const response = await apiClient.getChangelogStatus({
+ query: { version },
+ });
+ if (response.status === 200) return response.body;
+ return null;
}
);
diff --git a/apps/desktop/src/routes/(window-chrome)/settings/apps/s3-config.tsx b/apps/desktop/src/routes/(window-chrome)/settings/apps/s3-config.tsx
index 76d78920c..1b32d1c1b 100644
--- a/apps/desktop/src/routes/(window-chrome)/settings/apps/s3-config.tsx
+++ b/apps/desktop/src/routes/(window-chrome)/settings/apps/s3-config.tsx
@@ -4,6 +4,7 @@ import { createSignal, onMount } from "solid-js";
import { authStore } from "~/store";
import { clientEnv } from "~/utils/env";
import { commands } from "~/utils/tauri";
+import { apiClient as apiClient, protectedHeaders } from "~/utils/web-api";
interface S3Config {
provider: string;
@@ -56,51 +57,16 @@ export default function S3ConfigPage() {
window.close();
};
- const makeAuthenticatedRequest = async (
- url: string,
- options: RequestInit
- ) => {
- const auth = await authStore.get();
- if (!auth) {
- await handleAuthError();
- return null;
- }
-
- const response = await fetch(
- `${clientEnv.VITE_SERVER_URL}${url}?origin=${window.location.origin}`,
- {
- ...options,
- credentials: "include",
- headers: {
- ...options.headers,
- Authorization: `Bearer ${auth.token}`,
- },
- }
- );
-
- if (!response.ok) {
- throw new Error(
- `Failed to ${options.method?.toLowerCase() || "fetch"} S3 configuration`
- );
- }
-
- return response;
- };
-
onMount(async () => {
try {
- const response = await makeAuthenticatedRequest(
- "/api/desktop/s3/config/get",
- {
- method: "GET",
- }
- );
+ const response = await apiClient.getS3Config({
+ headers: await protectedHeaders(),
+ });
- if (!response) return;
+ if (response.status !== 200) throw new Error("Failed to fetch S3 config");
- const data = await response.json();
- if (data.config) {
- const config = data.config as S3Config;
+ if (response.body.config) {
+ const config = response.body.config;
if (!config.accessKeyId) return;
setProvider(config.provider || DEFAULT_CONFIG.provider);
@@ -123,25 +89,19 @@ export default function S3ConfigPage() {
const handleSave = async () => {
setSaving(true);
try {
- const response = await makeAuthenticatedRequest(
- "/api/desktop/s3/config",
- {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- },
- body: JSON.stringify({
- provider: provider(),
- accessKeyId: accessKeyId(),
- secretAccessKey: secretAccessKey(),
- endpoint: endpoint(),
- bucketName: bucketName(),
- region: region(),
- }),
- }
- );
+ const response = await apiClient.setS3Config({
+ body: {
+ provider: provider(),
+ accessKeyId: accessKeyId(),
+ secretAccessKey: secretAccessKey(),
+ endpoint: endpoint(),
+ bucketName: bucketName(),
+ region: region(),
+ },
+ headers: await protectedHeaders(),
+ });
- if (response) {
+ if (response.status === 200) {
setHasConfig(true);
await commands.globalMessageDialog(
"S3 configuration saved successfully"
@@ -160,14 +120,11 @@ export default function S3ConfigPage() {
const handleDelete = async () => {
setDeleting(true);
try {
- const response = await makeAuthenticatedRequest(
- "/api/desktop/s3/config/delete",
- {
- method: "DELETE",
- }
- );
+ const response = await apiClient.deleteS3Config({
+ headers: await protectedHeaders(),
+ });
- if (response) {
+ if (response.status === 200) {
resetForm();
await commands.globalMessageDialog(
"S3 configuration deleted successfully"
@@ -189,28 +146,21 @@ export default function S3ConfigPage() {
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), 5500); // 5.5s timeout (slightly longer than backend)
- const response = await makeAuthenticatedRequest(
- "/api/desktop/s3/config/test",
- {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- },
- body: JSON.stringify({
- provider: provider(),
- accessKeyId: accessKeyId(),
- secretAccessKey: secretAccessKey(),
- endpoint: endpoint(),
- bucketName: bucketName(),
- region: region(),
- }),
- signal: controller.signal,
- }
- );
+ const response = await apiClient.testS3Config({
+ body: {
+ provider: provider(),
+ accessKeyId: accessKeyId(),
+ secretAccessKey: secretAccessKey(),
+ endpoint: endpoint(),
+ bucketName: bucketName(),
+ region: region(),
+ },
+ headers: await protectedHeaders(),
+ });
clearTimeout(timeoutId);
- if (response) {
+ if (response.status === 200) {
await commands.globalMessageDialog(
"S3 configuration test successful! Connection is working."
);
diff --git a/apps/desktop/src/routes/(window-chrome)/settings/changelog.tsx b/apps/desktop/src/routes/(window-chrome)/settings/changelog.tsx
index 82b34a530..08d1df03f 100644
--- a/apps/desktop/src/routes/(window-chrome)/settings/changelog.tsx
+++ b/apps/desktop/src/routes/(window-chrome)/settings/changelog.tsx
@@ -1,28 +1,21 @@
-import { For, Show, createResource, ErrorBoundary, Suspense } from "solid-js";
-import { clientEnv } from "~/utils/env";
+import { For, Show, ErrorBoundary, Suspense } from "solid-js";
import { SolidMarkdown } from "solid-markdown";
import { createQuery } from "@tanstack/solid-query";
-import { AbsoluteInsetLoader } from "~/components/Loader";
import { cx } from "cva";
-interface ChangelogEntry {
- title: string;
- app: string;
- version: string;
- publishedAt: string;
- content: string;
-}
+import { AbsoluteInsetLoader } from "~/components/Loader";
+import { apiClient } from "~/utils/web-api";
export default function Page() {
const changelog = createQuery(() => ({
queryKey: ["changelog"],
queryFn: async () => {
- const response = await fetch(
- `${clientEnv.VITE_SERVER_URL}/api/changelog?origin=${window.location.origin}`
- );
- if (!response.ok) throw new Error("Failed to fetch changelog");
+ const response = await apiClient.getChangelogPosts({
+ query: { origin: window.location.origin },
+ });
- return (await response.json()) as Array<ChangelogEntry>;
+ if (response.status !== 200) throw new Error("Failed to fetch changelog");
+ return response.body;
},
}));
@@ -40,7 +33,9 @@ export default function Page() {
>
<ErrorBoundary
fallback={(e) => (
- <div class="text-[--text-primary] font-medium">{e.toString()}</div>
+ <div class="text-[--text-primary] font-medium">
+ {e.toString()}
+ </div>
)}
>
<ul class="space-y-8">
diff --git a/apps/desktop/src/routes/(window-chrome)/settings/feedback.tsx b/apps/desktop/src/routes/(window-chrome)/settings/feedback.tsx
index 7554e8e53..32df97ce0 100644
--- a/apps/desktop/src/routes/(window-chrome)/settings/feedback.tsx
+++ b/apps/desktop/src/routes/(window-chrome)/settings/feedback.tsx
@@ -1,71 +1,66 @@
import { createSignal } from "solid-js";
import { Button } from "@cap/ui-solid";
-import { commands } from "~/utils/tauri";
+import { action, useAction, useSubmission } from "@solidjs/router";
-export default function FeedbackTab() {
- const [feedback, setFeedback] = createSignal("");
- const [isSubmitting, setIsSubmitting] = createSignal(false);
- const [error, setError] = createSignal<string | null>(null);
- const [success, setSuccess] = createSignal(false);
+import { apiClient, protectedHeaders } from "~/utils/web-api";
+
+const sendFeedbackAction = action(async (feedback: string) => {
+ const response = await apiClient.submitDesktopFeedback({
+ body: { feedback },
+ headers: await protectedHeaders(),
+ });
- const handleSubmit = async (e: Event) => {
- e.preventDefault();
- if (!feedback().trim()) return;
+ if (response.status !== 200) throw new Error("Failed to submit feedback");
+ return response.body;
+});
- setIsSubmitting(true);
- setError(null);
- setSuccess(false);
+export default function FeedbackTab() {
+ const [feedback, setFeedback] = createSignal("");
- try {
- await commands.sendFeedbackRequest(feedback());
- setSuccess(true);
- setFeedback("");
- } catch (err) {
- console.error("Error submitting feedback:", err);
- setError(
- err instanceof Error ? err.message : "Failed to submit feedback"
- );
- } finally {
- setIsSubmitting(false);
- }
- };
+ const submission = useSubmission(sendFeedbackAction);
+ const sendFeedback = useAction(sendFeedbackAction);
return (
<div class="p-6 max-w-2xl">
- <h2 class="text-[--text-primary] text-lg font-medium mb-2">Send Feedback</h2>
+ <h2 class="text-[--text-primary] text-lg font-medium mb-2">
+ Send Feedback
+ </h2>
<p class="text-[--text-tertiary] mb-[1rem]">
Help us improve Cap by submitting feedback or reporting bugs. We'll get
right on it.
</p>
- <form class="space-y-4">
- <div>
- <textarea
- value={feedback()}
- onInput={(e) => setFeedback(e.currentTarget.value)}
- placeholder="Tell us what you think about Cap..."
- required
- minLength={10}
- class="w-full h-32 p-2 border border-[--gray-500] bg-[--gray-100] text-[--text-primary] rounded-md resize-none focus:outline-none focus:ring-2 focus:ring-[--blue-400]"
- disabled={isSubmitting()}
- />
- </div>
+ <form class="space-y-4" onSubmit={() => sendFeedback(feedback())}>
+ <fieldset disabled={submission.pending}>
+ <div>
+ <textarea
+ value={feedback()}
+ onInput={(e) => setFeedback(e.currentTarget.value)}
+ placeholder="Tell us what you think about Cap..."
+ required
+ minLength={10}
+ class="w-full h-32 p-2 border border-[--gray-500] bg-[--gray-100] text-[--text-primary] rounded-md resize-none focus:outline-none focus:ring-2 focus:ring-[--blue-400]"
+ />
+ </div>
- {error() && <p class="text-red-500 text-sm">{error()}</p>}
+ {submission.error && (
+ <p class="text-red-500 text-sm">{submission.error.toString()}</p>
+ )}
- {success() && (
- <p class="text-[--text-primary] text-sm">Thank you for your feedback!</p>
- )}
+ {submission.result?.success && (
+ <p class="text-[--text-primary] text-sm">
+ Thank you for your feedback!
+ </p>
+ )}
- <Button
- onClick={handleSubmit}
- type="button"
- disabled={
- isSubmitting() || !feedback().trim() || feedback().trim().length < 0
- }
- class="w-full bg-[--blue-400] text-[--text-primary]"
- >
- {isSubmitting() ? "Submitting..." : "Submit Feedback"}
- </Button>
+ <Button
+ type="submit"
+ onClick={() => console.log("bruh")}
+ disabled={!feedback().trim() || feedback().trim().length < 0}
+ class="w-full bg-[--blue-400] text-[--text-primary]"
+ >
+ {submission.pending ? "Submitting..." : "Submit Feedback"}
+ </Button>
+ </fieldset>
</form>
</div>
);
diff --git a/apps/desktop/src/routes/(window-chrome)/upgrade.tsx b/apps/desktop/src/routes/(window-chrome)/upgrade.tsx
index 09e44c186..791e8ad75 100644
--- a/apps/desktop/src/routes/(window-chrome)/upgrade.tsx
+++ b/apps/desktop/src/routes/(window-chrome)/upgrade.tsx
@@ -1,11 +1,12 @@
import { createSignal, onCleanup, onMount } from "solid-js";
-import { getProPlanId } from "~/utils/plans";
-import { commands } from "~/utils/tauri";
-import { clientEnv } from "~/utils/env";
-import { authStore } from "../../store";
import { Button } from "@cap/ui-solid";
import { getCurrentWindow } from "@tauri-apps/api/window";
+import { authStore } from "../../store";
+import { getProPlanId } from "~/utils/plans";
+import { commands } from "~/utils/tauri";
+import { apiClient, protectedHeaders } from "~/utils/web-api";
+
export default function Page() {
const proFeatures = [
"Unlimited cloud storage & Shareable links",
@@ -25,7 +26,7 @@ export default function Page() {
setIsAnnual(!isAnnual());
};
- const getCheckoutUrl = async () => {
+ const openCheckoutInExternalBrowser = async () => {
setLoading(true);
const planId = getProPlanId(isAnnual() ? "yearly" : "monthly");
@@ -39,21 +40,13 @@ export default function Page() {
return;
}
- const response = await fetch(
- `${clientEnv.VITE_SERVER_URL}/api/desktop/subscribe?origin=${window.location.origin}`,
- {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- Authorization: `Bearer ${auth.token}`,
- },
- body: JSON.stringify({ priceId: planId }),
- }
- );
+ const response = await apiClient.getProSubscribeURL({
+ body: { priceId: planId },
+ headers: await protectedHeaders(),
+ });
- if (response.ok) {
- const data = await response.json();
- commands.openExternalLink(data.url);
+ if (response.status === 200) {
+ commands.openExternalLink(response.body.url);
} else {
console.error("Failed to get checkout URL");
}
@@ -168,7 +161,7 @@ export default function Page() {
</div>
<div class="px-6 pb-4 pt-0">
<button
- onClick={getCheckoutUrl}
+ onClick={openCheckoutInExternalBrowser}
class="flex items-center justify-center rounded-full bg-[--gray-50] text-[--text-primary] hover:bg-[--gray-200] disabled:bg-[--gray-100] border border-[--gray-300] font-medium text-lg px-6 h-12 w-full no-underline"
disabled={loading()}
>
diff --git a/apps/desktop/src/routes/editor/ConfigSidebar.tsx b/apps/desktop/src/routes/editor/ConfigSidebar.tsx
index 07d7315dc..8cc05bf31 100644
--- a/apps/desktop/src/routes/editor/ConfigSidebar.tsx
+++ b/apps/desktop/src/routes/editor/ConfigSidebar.tsx
@@ -693,7 +693,7 @@ function RgbInput(props: {
const [text, setText] = createWritableMemo(() => rgbToHex(props.value));
let prevHex = rgbToHex(props.value);
- let colorInput: HTMLInputElement;
+ let colorInput!: HTMLInputElement;
return (
<div class="flex flex-row items-center gap-[0.75rem] relative">
@@ -706,7 +706,7 @@ function RgbInput(props: {
onClick={() => colorInput.click()}
/>
<input
- ref={colorInput!}
+ ref={colorInput}
type="color"
class="absolute left-0 bottom-0 w-[3rem] opacity-0"
onChange={(e) => {
diff --git a/apps/desktop/src/routes/editor/Editor.tsx b/apps/desktop/src/routes/editor/Editor.tsx
index 89761a20c..66124e475 100644
--- a/apps/desktop/src/routes/editor/Editor.tsx
+++ b/apps/desktop/src/routes/editor/Editor.tsx
@@ -335,8 +335,8 @@ function Dialogs() {
};
});
- let cropAreaRef: HTMLDivElement;
- let cropTargetRef: HTMLDivElement;
+ let cropAreaRef!: HTMLDivElement;
+ let cropTargetRef!: HTMLDivElement;
return (
<>
@@ -386,11 +386,7 @@ function Dialogs() {
</Dialog.Header>
<Dialog.Content>
<div class="flex flex-row justify-center">
- <div
- class="relative bg-blue-200"
- // biome-ignore lint/style/noNonNullAssertion: ref
- ref={cropAreaRef!}
- >
+ <div class="relative bg-blue-200" ref={cropAreaRef}>
<div class="divide-black-transparent-10 overflow-hidden rounded-lg">
<img
class="shadow pointer-events-none max-h-[70vh]"
@@ -402,8 +398,7 @@ function Dialogs() {
</div>
<div
class="bg-white-transparent-20 absolute cursor-move"
- // biome-ignore lint/style/noNonNullAssertion: ref
- ref={cropTargetRef!}
+ ref={cropTargetRef}
style={styles()}
onMouseDown={(downEvent) => {
const original = {
diff --git a/apps/desktop/src/routes/editor/Player.tsx b/apps/desktop/src/routes/editor/Player.tsx
index 348835ee7..9981dbbab 100644
--- a/apps/desktop/src/routes/editor/Player.tsx
+++ b/apps/desktop/src/routes/editor/Player.tsx
@@ -38,7 +38,7 @@ export function Player() {
setSplit,
} = useEditorContext();
- let canvasRef: HTMLCanvasElement;
+ let canvasRef!: HTMLCanvasElement;
createEffect(() => {
const frame = latestFrame();
@@ -207,8 +207,7 @@ export function Player() {
height: `${size().height}px`,
}}
class="bg-blue-50 absolute rounded"
- // biome-ignore lint/style/noNonNullAssertion: ref
- ref={canvasRef!}
+ ref={canvasRef}
id="canvas"
width={currentFrame().width}
height={currentFrame().height}
diff --git a/apps/desktop/src/utils/web-api.ts b/apps/desktop/src/utils/web-api.ts
new file mode 100644
index 000000000..517967e23
--- /dev/null
+++ b/apps/desktop/src/utils/web-api.ts
@@ -0,0 +1,40 @@
+import { initClient } from "@ts-rest/core";
+import { contract } from "@cap/web-api-contract";
+import { fetch } from "@tauri-apps/plugin-http";
+
+import { clientEnv } from "./env";
+import { authStore } from "~/store";
+
+const baseUrl = `${clientEnv.VITE_SERVER_URL}/api`;
+export const apiClient = initClient(contract, {
+ baseUrl,
+ api: async (args) => {
+ const resp = await fetch(args.path, args);
+
+ let body;
+
+ const contentType = resp.headers.get("content-type");
+ if (contentType === "application/json") {
+ body = await resp.json();
+ } else {
+ body = await resp.text();
+ }
+
+ return {
+ body,
+ status: resp.status,
+ headers: resp.headers,
+ };
+ },
+});
+
+export async function maybeProtectedHeaders() {
+ const token = (await authStore.get())?.token;
+ return { authorization: token ? `Bearer ${token}` : undefined };
+}
+
+export async function protectedHeaders() {
+ const { authorization } = await maybeProtectedHeaders();
+ if (!authorization) throw new Error("Not authorized");
+ return { authorization };
+}
diff --git a/apps/web/next.config.mjs b/apps/web/next.config.mjs
index 2dde732b2..dd804a5de 100644
--- a/apps/web/next.config.mjs
+++ b/apps/web/next.config.mjs
@@ -19,7 +19,7 @@ const { version } = packageJson;
const nextConfig = {
reactStrictMode: true,
swcMinify: true,
- transpilePackages: ["@cap/ui", "@cap/utils"],
+ transpilePackages: ["@cap/ui", "@cap/utils", "@cap/web-api-contract"],
eslint: {
ignoreDuringBuilds: true,
},
@@ -27,7 +27,7 @@ const nextConfig = {
ignoreBuildErrors: true,
},
experimental: {
- optimizePackageImports: ["@cap/ui", "@cap/utils"],
+ optimizePackageImports: ["@cap/ui", "@cap/utils", "@cap/web-api-contract"],
serverComponentsExternalPackages: [
"@react-email/components",
"@react-email/render",
diff --git a/packages/ui-solid/src/Button.tsx b/packages/ui-solid/src/Button.tsx
index 1e7f4d962..9a441a911 100644
--- a/packages/ui-solid/src/Button.tsx
+++ b/packages/ui-solid/src/Button.tsx
@@ -34,8 +34,8 @@ export function Button(
) {
return (
<button
- {...props}
type="button"
+ {...props}
class={styles({ ...props, class: props.class })}
/>
);
diff --git a/packages/web-api-contract/src/index.ts b/packages/web-api-contract/src/index.ts
index 304deefa9..d83f9b8a7 100644
--- a/packages/web-api-contract/src/index.ts
+++ b/packages/web-api-contract/src/index.ts
@@ -19,13 +19,21 @@ const publicContract = c.router({
getChangelogPosts: {
method: "GET",
path: "/changelog",
+ query: z.object({
+ origin: z.string(),
+ }),
responses: {
- 200: z.array(CHANGELOG),
+ 200: z.array(
+ z.object({ content: z.string() }).and(CHANGELOG.shape.metadata)
+ ),
},
},
getChangelogStatus: {
method: "GET",
path: "/changelog/status",
+ query: z.object({
+ version: z.string(),
+ }),
responses: {
200: z.object({ hasUpdate: z.boolean() }),
},
@@ -50,14 +58,79 @@ const protectedContract = c.router(
200: z.object({ upgraded: z.boolean() }),
},
},
+ getS3Config: {
+ method: "GET",
+ path: "/desktop/s3/config/get",
+ responses: {
+ 200: z.object({
+ config: z.custom<{
+ provider: string;
+ accessKeyId: string | null;
+ secretAccessKey: string | null;
+ endpoint: string | null;
+ bucketName: string | null;
+ region: string | null;
+ }>(),
+ }),
+ },
+ },
+ setS3Config: {
+ method: "POST",
+ path: "/desktop/s3/config",
+ responses: {
+ 200: z.object({ success: z.literal(true) }),
+ },
+ body: z.object({
+ provider: z.string(),
+ accessKeyId: z.string(),
+ secretAccessKey: z.string(),
+ endpoint: z.string(),
+ bucketName: z.string(),
+ region: z.string(),
+ }),
+ },
+ deleteS3Config: {
+ method: "DELETE",
+ path: "/dekstop/s3/config/delete",
+ responses: { 200: z.object({ success: z.literal(true) }) },
+ },
+ testS3Config: {
+ method: "POST",
+ path: "/desktop/s3/config/test",
+ body: z.object({
+ provider: z.string(),
+ accessKeyId: z.string(),
+ secretAccessKey: z.string(),
+ endpoint: z.string(),
+ bucketName: z.string(),
+ region: z.string(),
+ }),
+ responses: { 200: z.object({ success: z.literal(true) }) },
+ },
+ getProSubscribeURL: {
+ method: "POST",
+ path: "/desktop/subscribe",
+ body: z.object({ priceId: z.string() }),
+ responses: {
+ 200: z.object({ url: z.string() }),
+ 400: z.object({
+ error: z.literal(true),
+ subscription: z.literal(true).optional(),
+ }),
+ 401: z.object({
+ error: z.literal(true),
+ auth: z.literal(false),
+ }),
+ },
+ },
},
{
- baseHeaders: z.object({ authorization: z.string().optional() }),
+ baseHeaders: z.object({ authorization: z.string() }),
commonResponses: { 401: z.object({ error: z.string().or(z.boolean()) }) },
}
);
export const contract = c.router({
- public: publicContract,
- protected: protectedContract,
+ ...publicContract,
+ ...protectedContract,
});
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 9cc2d0377..16e44579b 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -46,6 +46,9 @@ importers:
'@cap/utils':
specifier: workspace:*
version: link:../../packages/utils
+ '@cap/web-api-contract':
+ specifier: workspace:*
+ version: link:../../packages/web-api-contract
'@corvu/tooltip':
specifier: ^0.2.1
version: 0.2.1([email protected])
@@ -133,6 +136,9 @@ importers:
'@tauri-apps/plugin-updater':
specifier: 2.0.0-rc.0
version: 2.0.0-rc.0
+ '@ts-rest/core':
+ specifier: ^3.51.0
+ version: 3.51.0(@types/[email protected])([email protected])
'@types/react-tooltip':
specifier: ^4.2.4
@@ -17809,7 +17815,7 @@ snapshots:
doctrine: 2.1.0
eslint: 8.57.1
eslint-import-resolver-node: 0.3.9
hasown: 2.0.2
is-core-module: 2.15.1
is-glob: 4.0.3