diff options
| author | MohamedBassem <me@mbassem.com> | 2024-04-02 15:12:40 +0100 |
|---|---|---|
| committer | MohamedBassem <me@mbassem.com> | 2024-04-02 15:12:40 +0100 |
| commit | d4406729df2d285729ab9f2ad3301e0d726ef164 (patch) | |
| tree | bfba411c289c0c0e97d760b83844de0d5dc18333 /apps/cli/lib | |
| parent | 79321f83293bc37d37af4b0a0b2bd324f5bafe1a (diff) | |
| download | karakeep-d4406729df2d285729ab9f2ad3301e0d726ef164.tar.zst | |
featuer: Introduce a new CLI for mass manipulation of bookmarks
Diffstat (limited to 'apps/cli/lib')
| -rw-r--r-- | apps/cli/lib/globals.ts | 17 | ||||
| -rw-r--r-- | apps/cli/lib/trpc.ts | 23 |
2 files changed, 40 insertions, 0 deletions
diff --git a/apps/cli/lib/globals.ts b/apps/cli/lib/globals.ts new file mode 100644 index 00000000..771136da --- /dev/null +++ b/apps/cli/lib/globals.ts @@ -0,0 +1,17 @@ +export interface GlobalOptions { + apiKey: string; + serverAddr: string; +} + +export let globalOpts: GlobalOptions | undefined = undefined; + +export function setGlobalOptions(opts: GlobalOptions) { + globalOpts = opts; +} + +export function getGlobalOptions() { + if (!globalOpts) { + throw new Error("Global options are not initalized yet"); + } + return globalOpts; +} diff --git a/apps/cli/lib/trpc.ts b/apps/cli/lib/trpc.ts new file mode 100644 index 00000000..6f0dccfe --- /dev/null +++ b/apps/cli/lib/trpc.ts @@ -0,0 +1,23 @@ +import { createTRPCClient, httpBatchLink } from "@trpc/client"; +import superjson from "superjson"; + +import type { AppRouter } from "@hoarder/trpc/routers/_app"; + +import { getGlobalOptions } from "./globals"; + +export function getAPIClient() { + const globals = getGlobalOptions(); + return createTRPCClient<AppRouter>({ + links: [ + httpBatchLink({ + url: `${globals.serverAddr}/api/trpc`, + transformer: superjson, + headers() { + return { + authorization: `Bearer ${globals.apiKey}`, + }; + }, + }), + ], + }); +} |
