diff options
Diffstat (limited to 'packages/auth-apikey')
| -rw-r--r-- | packages/auth-apikey/package.json | 18 | ||||
| -rw-r--r-- | packages/auth-apikey/src/extension.ts | 28 | ||||
| -rw-r--r-- | packages/auth-apikey/src/resolver.test.ts | 58 | ||||
| -rw-r--r-- | packages/auth-apikey/src/resolver.ts | 14 | ||||
| -rw-r--r-- | packages/auth-apikey/tsconfig.json | 8 |
5 files changed, 63 insertions, 63 deletions
diff --git a/packages/auth-apikey/package.json b/packages/auth-apikey/package.json index 74ee65f..db6e7b6 100644 --- a/packages/auth-apikey/package.json +++ b/packages/auth-apikey/package.json @@ -1,11 +1,11 @@ { - "name": "@dispatch/auth-apikey", - "version": "0.0.0", - "type": "module", - "private": true, - "main": "dist/index.js", - "types": "dist/index.d.ts", - "dependencies": { - "@dispatch/kernel": "workspace:*" - } + "name": "@dispatch/auth-apikey", + "version": "0.0.0", + "type": "module", + "private": true, + "main": "dist/index.js", + "types": "dist/index.d.ts", + "dependencies": { + "@dispatch/kernel": "workspace:*" + } } diff --git a/packages/auth-apikey/src/extension.ts b/packages/auth-apikey/src/extension.ts index 05d6462..ee68b60 100644 --- a/packages/auth-apikey/src/extension.ts +++ b/packages/auth-apikey/src/extension.ts @@ -2,21 +2,21 @@ import type { AuthContract, Extension } from "@dispatch/kernel"; import { resolveApiKeyCredentials } from "./resolver.js"; export const apikeyAuth: AuthContract = { - id: "apikey", - resolve: async () => - resolveApiKeyCredentials(process.env as Readonly<Record<string, string | undefined>>), + id: "apikey", + resolve: async () => + resolveApiKeyCredentials(process.env as Readonly<Record<string, string | undefined>>), }; export const extension: Extension = { - manifest: { - id: "auth-apikey", - name: "API Key Auth", - version: "0.0.0", - apiVersion: "^0.1.0", - trust: "bundled", - contributes: { auth: ["apikey"] }, - }, - activate(host) { - host.defineAuth(apikeyAuth); - }, + manifest: { + id: "auth-apikey", + name: "API Key Auth", + version: "0.0.0", + apiVersion: "^0.1.0", + trust: "bundled", + contributes: { auth: ["apikey"] }, + }, + activate(host) { + host.defineAuth(apikeyAuth); + }, }; diff --git a/packages/auth-apikey/src/resolver.test.ts b/packages/auth-apikey/src/resolver.test.ts index d6c1f85..bef734d 100644 --- a/packages/auth-apikey/src/resolver.test.ts +++ b/packages/auth-apikey/src/resolver.test.ts @@ -2,36 +2,36 @@ import { describe, expect, it } from "vitest"; import { resolveApiKeyCredentials } from "./resolver.js"; describe("resolveApiKeyCredentials", () => { - it("resolves key with default baseURL from minimal env", () => { - const env = { DISPATCH_API_KEY: "sk-test-123" }; - const result = resolveApiKeyCredentials(env); - expect(result).toEqual({ - type: "api-key", - apiKey: "sk-test-123", - baseURL: "https://opencode.ai/zen/go/v1", - }); - }); + it("resolves key with default baseURL from minimal env", () => { + const env = { DISPATCH_API_KEY: "sk-test-123" }; + const result = resolveApiKeyCredentials(env); + expect(result).toEqual({ + type: "api-key", + apiKey: "sk-test-123", + baseURL: "https://opencode.ai/zen/go/v1", + }); + }); - it("honors an explicit DISPATCH_BASE_URL", () => { - const env = { - DISPATCH_API_KEY: "sk-test-456", - DISPATCH_BASE_URL: "https://custom.example.com/v2", - }; - const result = resolveApiKeyCredentials(env); - expect(result).toEqual({ - type: "api-key", - apiKey: "sk-test-456", - baseURL: "https://custom.example.com/v2", - }); - }); + it("honors an explicit DISPATCH_BASE_URL", () => { + const env = { + DISPATCH_API_KEY: "sk-test-456", + DISPATCH_BASE_URL: "https://custom.example.com/v2", + }; + const result = resolveApiKeyCredentials(env); + expect(result).toEqual({ + type: "api-key", + apiKey: "sk-test-456", + baseURL: "https://custom.example.com/v2", + }); + }); - it("throws a clear error when DISPATCH_API_KEY is absent", () => { - const env = {}; - expect(() => resolveApiKeyCredentials(env)).toThrow("DISPATCH_API_KEY"); - }); + it("throws a clear error when DISPATCH_API_KEY is absent", () => { + const env = {}; + expect(() => resolveApiKeyCredentials(env)).toThrow("DISPATCH_API_KEY"); + }); - it("throws when DISPATCH_API_KEY is empty string", () => { - const env = { DISPATCH_API_KEY: "" }; - expect(() => resolveApiKeyCredentials(env)).toThrow("DISPATCH_API_KEY"); - }); + it("throws when DISPATCH_API_KEY is empty string", () => { + const env = { DISPATCH_API_KEY: "" }; + expect(() => resolveApiKeyCredentials(env)).toThrow("DISPATCH_API_KEY"); + }); }); diff --git a/packages/auth-apikey/src/resolver.ts b/packages/auth-apikey/src/resolver.ts index 2e63a1c..a90c45e 100644 --- a/packages/auth-apikey/src/resolver.ts +++ b/packages/auth-apikey/src/resolver.ts @@ -3,12 +3,12 @@ import type { ApiKeyCredentials } from "@dispatch/kernel"; const DEFAULT_BASE_URL = "https://opencode.ai/zen/go/v1"; export function resolveApiKeyCredentials( - env: Readonly<Record<string, string | undefined>>, + env: Readonly<Record<string, string | undefined>>, ): ApiKeyCredentials { - const apiKey = env.DISPATCH_API_KEY; - if (!apiKey) { - throw new Error("DISPATCH_API_KEY is not set. Set it in your environment or .env file."); - } - const baseURL = env.DISPATCH_BASE_URL ?? DEFAULT_BASE_URL; - return { type: "api-key", apiKey, baseURL }; + const apiKey = env.DISPATCH_API_KEY; + if (!apiKey) { + throw new Error("DISPATCH_API_KEY is not set. Set it in your environment or .env file."); + } + const baseURL = env.DISPATCH_BASE_URL ?? DEFAULT_BASE_URL; + return { type: "api-key", apiKey, baseURL }; } diff --git a/packages/auth-apikey/tsconfig.json b/packages/auth-apikey/tsconfig.json index ff99a43..44ed916 100644 --- a/packages/auth-apikey/tsconfig.json +++ b/packages/auth-apikey/tsconfig.json @@ -1,6 +1,6 @@ { - "extends": "../../tsconfig.base.json", - "compilerOptions": { "rootDir": "src", "outDir": "dist", "composite": true }, - "include": ["src/**/*.ts"], - "references": [{ "path": "../kernel" }] + "extends": "../../tsconfig.base.json", + "compilerOptions": { "rootDir": "src", "outDir": "dist", "composite": true }, + "include": ["src/**/*.ts"], + "references": [{ "path": "../kernel" }] } |
