summaryrefslogtreecommitdiffhomepage
path: root/packages/auth-apikey/src
diff options
context:
space:
mode:
Diffstat (limited to 'packages/auth-apikey/src')
-rw-r--r--packages/auth-apikey/src/extension.ts28
-rw-r--r--packages/auth-apikey/src/resolver.test.ts58
-rw-r--r--packages/auth-apikey/src/resolver.ts14
3 files changed, 50 insertions, 50 deletions
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 };
}