Skip to content

Commit 0c1cac4

Browse files
committed
feat: management test (WIP)
1 parent 7f9be32 commit 0c1cac4

File tree

9 files changed

+1923
-169
lines changed

9 files changed

+1923
-169
lines changed

apps/server/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { OpenAPIHono } from "@hono/zod-openapi";
22
import { Hono } from "hono";
33
import { prettyJSON } from "hono/pretty-json";
44
import { secureHeaders } from "hono/secure-headers";
5+
import { authMiddleware } from "./middleware/auth";
56
import { corsMiddleware } from "./middleware/cors";
67
import { logging } from "./middleware/logging";
78
import { acquisitionRouter } from "./routes/acquisition";

apps/server/src/routes/management.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { OpenAPIHono, createRoute } from "@hono/zod-openapi";
22
import { HTTPException } from "hono/http-exception";
33
import { z } from "zod";
4+
import { authMiddleware } from "../middleware/auth";
45
import { getStorageProvider } from "../storage/factory";
56
import type { Env } from "../types/env";
67
import {
@@ -26,6 +27,8 @@ import {
2627

2728
const router = new OpenAPIHono<Env>();
2829

30+
router.use("/*", authMiddleware());
31+
2932
const DEFAULT_ACCESS_KEY_EXPIRY = 1000 * 60 * 60 * 24 * 60; // 60 days
3033
const ACCESS_KEY_MASKING_STRING = "(hidden)";
3134

apps/server/src/utils/errors.ts

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Context } from "hono";
22
import { HTTPException } from "hono/http-exception";
3-
import { ErrorCode, type StorageError } from "../types/storage";
3+
import { isStorageError } from "../types/error";
44

55
export class AppError extends Error {
66
constructor(
@@ -71,7 +71,6 @@ export function handleError(error: unknown, c: Context): Response {
7171
}
7272

7373
if (isStorageError(error)) {
74-
// const statusCode = storageErrorToStatusCode(error.code);
7574
return c.json({
7675
error: "STORAGE_ERROR",
7776
error_description: error.message,
@@ -86,31 +85,3 @@ export function handleError(error: unknown, c: Context): Response {
8685
500,
8786
);
8887
}
89-
90-
function isStorageError(error: unknown): error is StorageError {
91-
return (
92-
typeof error === "object" &&
93-
error !== null &&
94-
"code" in error &&
95-
"source" in error &&
96-
error.source === "storage"
97-
);
98-
}
99-
function storageErrorToStatusCode(code: ErrorCode): number {
100-
switch (code) {
101-
case ErrorCode.NotFound:
102-
return 404;
103-
case ErrorCode.AlreadyExists:
104-
return 409;
105-
case ErrorCode.Invalid:
106-
return 400;
107-
case ErrorCode.Expired:
108-
return 401;
109-
case ErrorCode.TooLarge:
110-
return 413;
111-
case ErrorCode.ConnectionFailed:
112-
return 503;
113-
default:
114-
return 500;
115-
}
116-
}

apps/server/src/utils/middleware.ts

Lines changed: 0 additions & 101 deletions
This file was deleted.

apps/server/src/utils/package-differ.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ class PackageDifferImpl implements PackageDiffer {
172172

173173
// Get deployment info to update history
174174
const deployment = await storage.getDeploymentInfo(
175-
latestPackage.deploymentId, // Changed from deploymentKey to deploymentId
175+
latestPackage.originalDeployment,
176176
);
177177

178178
await storage.updatePackageHistory(

apps/server/test/env.d.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
declare module "cloudflare:test" {
22
// Controls the type of `import("cloudflare:test").env`
33
interface ProvidedEnv extends Env {
4+
TEST_MIGRATIONS: D1Migration[];
45
DB: D1Database;
56
STORAGE_BUCKET: R2Bucket;
6-
TEST_MIGRATIONS: D1Migration[];
7+
GITHUB_CLIENT_ID: string;
8+
GITHUB_CLIENT_SECRET: string;
9+
SERVER_URL: string;
10+
JWT_SECRET: string;
11+
ENABLE_ACCOUNT_REGISTRATION: string;
12+
CORS_ORIGINS: string;
13+
ACCOUNT_ID: string;
14+
R2_BUCKET_NAME: string;
15+
R2_ACCESS_KEY_ID: string;
16+
R2_SECRET_ACCESS_KEY: string;
717
}
818
}

0 commit comments

Comments
 (0)