diff --git a/api/README.md b/api/README.md index 886a95f45..a8c963da9 100644 --- a/api/README.md +++ b/api/README.md @@ -56,12 +56,9 @@ Here is a list of endpoints that have changed in this release. Old endpoints wil |Old|New| |-|- -|`/predicted-block-date//` | `/predicted-block-date/?blockWindow=` -|`/predicted-date-height//` | `/predicted-date-height/?blockWindow=` -|`/getNetworkCapacity`|`/network-capacity` -|`/marketData`|`/market-data` |`/dashboardData`|`/dashboard-data` -|`getMainnetNodes`|`/nodes/mainnet` +|`/getNetworkCapacity`|`/network-capacity` +|`/getMainnetNodes`|`/nodes/mainnet` |`/getSandboxNodes`|`/nodes/sandbox` |`/getTestnetNodes`|`/nodes/testnet` |`/getProviderAttributesSchema`|`/provider-attributes-schema` @@ -70,4 +67,8 @@ Here is a list of endpoints that have changed in this release. Old endpoints wil |`/getTestnetVersion`|`/version/testnet` |`/getProviderGraphData/`|`/provider-graph-data/` |`/getProviderActiveLeasesGraphData/
`|`/provider-active-leases-graph-data/
` -|`/getGraphData/`|`/graph-data/` \ No newline at end of file +|`/getGraphData/`|`/graph-data/` +|`/marketData`|`/market-data` +|`/predicted-block-date//` | `/predicted-block-date/?blockWindow=` +|`/predicted-date-height//` | `/predicted-date-height/?blockWindow=` +|`/providers//deployments///`|`/providers//deployments//?status=` \ No newline at end of file diff --git a/api/src/routers/legacyRouter.ts b/api/src/routers/legacyRouter.ts index 2c111c48a..cd93af564 100644 --- a/api/src/routers/legacyRouter.ts +++ b/api/src/routers/legacyRouter.ts @@ -4,6 +4,16 @@ export const legacyRouter = new Hono(); const redirectStatusCode = 302; // Temporary Redirect +legacyRouter.get("/blocks", async (c) => { + const limit = c.req.query("limit"); + return c.redirect(`/v1/blocks${limit ? `?limit=${limit}` : ""}`, redirectStatusCode); +}); + +legacyRouter.get("/blocks/:height", async (c) => { + const height = c.req.param("height"); + return c.redirect(`/v1/blocks/${height}`, redirectStatusCode); +}); + legacyRouter.get("/predicted-block-date/:height/:blockWindow?", async (c) => { const height = c.req.param("height"); const blockWindow = c.req.param("blockWindow"); @@ -18,6 +28,82 @@ legacyRouter.get("/predicted-date-height/:date/:blockWindow?", async (c) => { return c.redirect(`/v1/predicted-date-height/${date}${blockWindow ? `?blockWindow=${blockWindow}` : ""}`, redirectStatusCode); }); +legacyRouter.get("/transactions", async (c) => { + const limit = c.req.query("limit"); + return c.redirect(`/v1/transactions${limit ? `?limit=${limit}` : ""}`, redirectStatusCode); +}); + +legacyRouter.get("/transactions/:hash", async (c) => { + const hash = c.req.param("hash"); + return c.redirect(`/v1/transactions/${hash}`, redirectStatusCode); +}); + +legacyRouter.get("/addresses/:address", async (c) => { + const address = c.req.param("address"); + return c.redirect(`/v1/addresses/${address}`, redirectStatusCode); +}); + +legacyRouter.get("/addresses/:address/transactions/:skip/:limit", async (c) => { + const address = c.req.param("address"); + const skip = c.req.param("skip"); + const limit = c.req.param("limit"); + return c.redirect(`/v1/addresses/${address}/transactions/${skip}/${limit}`, redirectStatusCode); +}); + +legacyRouter.get("/addresses/:address/deployments/:skip/:limit", async (c) => { + const address = c.req.param("address"); + const skip = c.req.param("skip"); + const limit = c.req.param("limit"); + return c.redirect(`/v1/addresses/${address}/deployments/${skip}/${limit}`, redirectStatusCode); +}); + +legacyRouter.get("/providers/:address", async (c) => { + const address = c.req.param("address"); + return c.redirect(`/v1/providers/${address}`, redirectStatusCode); +}); + +legacyRouter.get("/providers", async (c) => { + return c.redirect("/v1/providers", redirectStatusCode); +}); + +legacyRouter.get("/providers/:provider/deployments/:skip/:limit/:status?", async (c) => { + const provider = c.req.param("provider"); + const skip = c.req.param("skip"); + const limit = c.req.param("limit"); + const status = c.req.param("status"); + return c.redirect(`/v1/providers/${provider}/deployments/${skip}/${limit}${status ? `?status=${status}` : ""}`, redirectStatusCode); +}); + +legacyRouter.get("/provider-attributes-schema", async (c) => { + return c.redirect("/v1/provider-attributes-schema", redirectStatusCode); +}); + +legacyRouter.get("/provider-regions", async (c) => { + return c.redirect("/v1/provider-regions", redirectStatusCode); +}); + +legacyRouter.get("/validators", async (c) => { + return c.redirect("/v1/validators", redirectStatusCode); +}); + +legacyRouter.get("/validators/:address", async (c) => { + const address = c.req.param("address"); + return c.redirect(`/v1/validators/${address}`, redirectStatusCode); +}); + +legacyRouter.get("/proposals", async (c) => { + return c.redirect("/v1/proposals", redirectStatusCode); +}); + +legacyRouter.get("/proposals/:id", async (c) => { + const id = c.req.param("id"); + return c.redirect(`/v1/proposals/${id}`, redirectStatusCode); +}); + +legacyRouter.get("/templates", async (c) => { + return c.redirect("/v1/templates", redirectStatusCode); +}); + legacyRouter.get("/getNetworkCapacity", async (c) => { return c.redirect("/v1/network-capacity", redirectStatusCode); }); @@ -30,6 +116,10 @@ legacyRouter.get("/dashboardData", async (c) => { return c.redirect("/v1/dashboard-data", redirectStatusCode); }); +legacyRouter.get("/pricing", async (c) => { + return c.redirect("/v1/pricing", redirectStatusCode); +}); + legacyRouter.get("/getAuditors", async (c) => { return c.redirect("/v1/auditors", redirectStatusCode); }); @@ -62,6 +152,12 @@ legacyRouter.get("/getTestnetVersion", async (c) => { return c.redirect("/v1/version/testnet", redirectStatusCode); }); +legacyRouter.get("/deployment/:owner/:dseq", async (c) => { + const owner = c.req.param("owner"); + const dseq = c.req.param("dseq"); + return c.redirect(`/v1/deployment/${owner}/${dseq}`, redirectStatusCode); +}); + legacyRouter.get("/getProviderGraphData/:dataName", async (c) => { const dataName = c.req.param("dataName"); return c.redirect(`/v1/provider-graph-data/${dataName}`, redirectStatusCode); diff --git a/api/src/routes/v1/addresses/deployments.ts b/api/src/routes/v1/addresses/deployments.ts index 9ff58c924..8b4923b96 100644 --- a/api/src/routes/v1/addresses/deployments.ts +++ b/api/src/routes/v1/addresses/deployments.ts @@ -2,6 +2,8 @@ import { OpenAPIHono, createRoute, z } from "@hono/zod-openapi"; import { getAddressDeployments } from "@src/services/external/apiNodeService"; import { openApiExampleAddress } from "@src/utils/constants"; +const maxLimit = 100; + const route = createRoute({ method: "get", path: "/addresses/{address}/deployments/{skip}/{limit}", @@ -19,7 +21,8 @@ const route = createRoute({ }), limit: z.string().openapi({ description: "Deployments to return", - example: "10" + example: "10", + maximum: maxLimit }) }), query: z.object({ @@ -27,7 +30,6 @@ const route = createRoute({ .string() .optional() .openapi({ - param: { name: "status", in: "query" }, description: "Filter by status", // TODO: Set possible statuses? example: "closed" }), @@ -69,7 +71,7 @@ const route = createRoute({ export default new OpenAPIHono().openapi(route, async (c) => { const skip = parseInt(c.req.valid("param").skip); - const limit = Math.min(100, parseInt(c.req.valid("param").limit)); + const limit = Math.min(maxLimit, parseInt(c.req.valid("param").limit)); // TODO Add param validation diff --git a/api/src/routes/v1/addresses/transactions.ts b/api/src/routes/v1/addresses/transactions.ts index dde23df44..f974fff3a 100644 --- a/api/src/routes/v1/addresses/transactions.ts +++ b/api/src/routes/v1/addresses/transactions.ts @@ -3,6 +3,8 @@ import { getTransactionByAddress } from "@src/services/db/transactionsService"; import { isValidBech32Address } from "@src/utils/addresses"; import { openApiExampleAddress } from "@src/utils/constants"; +const maxLimit = 100; + const route = createRoute({ method: "get", path: "/addresses/{address}/transactions/{skip}/{limit}", @@ -20,7 +22,8 @@ const route = createRoute({ }), limit: z.string().openapi({ description: "Transactions to return", - example: "10" + example: "10", + maximum: maxLimit }) }) }, @@ -69,7 +72,7 @@ export default new OpenAPIHono().openapi(route, async (c) => { } const skip = parseInt(c.req.valid("param").skip); - const limit = Math.min(100, parseInt(c.req.valid("param").limit)); + const limit = Math.min(maxLimit, parseInt(c.req.valid("param").limit)); if (isNaN(skip)) { return c.text("Invalid skip.", 400); @@ -77,7 +80,6 @@ export default new OpenAPIHono().openapi(route, async (c) => { if (isNaN(limit)) { return c.text("Invalid limit.", 400); - return; } const txs = await getTransactionByAddress(c.req.valid("param").address, skip, limit); diff --git a/api/src/routes/v1/blocks/list.ts b/api/src/routes/v1/blocks/list.ts index 92092bed3..d1293588f 100644 --- a/api/src/routes/v1/blocks/list.ts +++ b/api/src/routes/v1/blocks/list.ts @@ -10,7 +10,7 @@ const route = createRoute({ tags: ["Blocks"], request: { query: z.object({ - limit: z.string().openapi({ + limit: z.string().optional().openapi({ type: "number", minimum: 1, maximum: 100, diff --git a/api/src/routes/v1/providerAttributesSchema.ts b/api/src/routes/v1/providerAttributesSchema.ts index a7b82d9ee..cb5df41f4 100644 --- a/api/src/routes/v1/providerAttributesSchema.ts +++ b/api/src/routes/v1/providerAttributesSchema.ts @@ -1,7 +1,7 @@ import { OpenAPIHono, createRoute, z } from "@hono/zod-openapi"; import { getProviderAttributesSchema } from "@src/services/external/githubService"; -const attributeSChemaType = z.object({ +const attributeSchemaType = z.object({ key: z.string(), type: z.enum(["string", "number", "boolean", "option", "multiple-option"]), required: z.boolean(), @@ -28,33 +28,33 @@ const route = createRoute({ content: { "application/json": { schema: z.object({ - host: attributeSChemaType, - email: attributeSChemaType, - organization: attributeSChemaType, - website: attributeSChemaType, - tier: attributeSChemaType, - "status-page": attributeSChemaType, - "location-region": attributeSChemaType, - country: attributeSChemaType, - city: attributeSChemaType, - timezone: attributeSChemaType, - "location-type": attributeSChemaType, - "hosting-provider": attributeSChemaType, - "hardware-cpu": attributeSChemaType, - "hardware-cpu-arch": attributeSChemaType, - "hardware-gpu": attributeSChemaType, - "hardware-gpu-model": attributeSChemaType, - "hardware-disk": attributeSChemaType, - "hardware-memory": attributeSChemaType, - "network-provider": attributeSChemaType, - "network-speed-up": attributeSChemaType, - "network-speed-down": attributeSChemaType, - "feat-persistent-storage": attributeSChemaType, - "feat-persistent-storage-type": attributeSChemaType, - "workload-support-chia": attributeSChemaType, - "workload-support-chia-capabilities": attributeSChemaType, - "feat-endpoint-ip": attributeSChemaType, - "feat-endpoint-custom-domain": attributeSChemaType + host: attributeSchemaType, + email: attributeSchemaType, + organization: attributeSchemaType, + website: attributeSchemaType, + tier: attributeSchemaType, + "status-page": attributeSchemaType, + "location-region": attributeSchemaType, + country: attributeSchemaType, + city: attributeSchemaType, + timezone: attributeSchemaType, + "location-type": attributeSchemaType, + "hosting-provider": attributeSchemaType, + "hardware-cpu": attributeSchemaType, + "hardware-cpu-arch": attributeSchemaType, + "hardware-gpu": attributeSchemaType, + "hardware-gpu-model": attributeSchemaType, + "hardware-disk": attributeSchemaType, + "hardware-memory": attributeSchemaType, + "network-provider": attributeSchemaType, + "network-speed-up": attributeSchemaType, + "network-speed-down": attributeSchemaType, + "feat-persistent-storage": attributeSchemaType, + "feat-persistent-storage-type": attributeSchemaType, + "workload-support-chia": attributeSchemaType, + "workload-support-chia-capabilities": attributeSchemaType, + "feat-endpoint-ip": attributeSchemaType, + "feat-endpoint-custom-domain": attributeSchemaType }) } } diff --git a/api/src/routes/v1/providers/deployments.ts b/api/src/routes/v1/providers/deployments.ts index 12a4d0775..706d3f300 100644 --- a/api/src/routes/v1/providers/deployments.ts +++ b/api/src/routes/v1/providers/deployments.ts @@ -2,9 +2,11 @@ import { OpenAPIHono, createRoute, z } from "@hono/zod-openapi"; import { getProviderDeployments, getProviderDeploymentsCount } from "@src/services/db/deploymentService"; import { openApiExampleProviderAddress } from "@src/utils/constants"; +const maxLimit = 100; + const route = createRoute({ method: "get", - path: "/providers/{provider}/deployments/{skip}/{limit}/{status}", // TODO: Put back status as optional, + path: "/providers/{provider}/deployments/{skip}/{limit}", summary: "Get a list of deployments for a provider.", tags: ["Providers", "Deployments"], request: { @@ -19,12 +21,19 @@ const route = createRoute({ }), limit: z.string().openapi({ description: "Deployments to return", - example: "10" - }), - status: z.string().optional().openapi({ - description: "Filter by status", // TODO: Set possible statuses? - example: "closed" + example: "10", + maximum: maxLimit }) + }), + query: z.object({ + status: z + .string() + .optional() + .openapi({ + description: "Filter by status", + enum: ["active", "closed"], + example: "closed" + }) }) }, responses: { @@ -83,8 +92,8 @@ const route = createRoute({ export default new OpenAPIHono().openapi(route, async (c) => { const skip = parseInt(c.req.valid("param").skip); - const limit = Math.min(100, parseInt(c.req.valid("param").limit)); - const statusParam = c.req.valid("param").status as "active" | "closed" | undefined; + const limit = Math.min(maxLimit, parseInt(c.req.valid("param").limit)); + const statusParam = c.req.query("status") as "active" | "closed" | undefined; // TODO: Validate skip/limit if (statusParam && statusParam !== "active" && statusParam !== "closed") { return c.text(`Invalid status filter: "${statusParam}". Valid values are "active" and "closed".`, 400); diff --git a/api/src/routes/v1/validators/byAddress.ts b/api/src/routes/v1/validators/byAddress.ts index 2f6e92ca0..edd18e62a 100644 --- a/api/src/routes/v1/validators/byAddress.ts +++ b/api/src/routes/v1/validators/byAddress.ts @@ -58,5 +58,5 @@ export default new OpenAPIHono().openapi(route, async (c) => { return c.text("Validator not found", 404); } - c.json(validator); + return c.json(validator); }); diff --git a/api/src/routes/v1/validators/list.ts b/api/src/routes/v1/validators/list.ts index 1519393b4..85506129e 100644 --- a/api/src/routes/v1/validators/list.ts +++ b/api/src/routes/v1/validators/list.ts @@ -5,10 +5,9 @@ const route = createRoute({ method: "get", path: "/validators", tags: ["Validators"], - request: {}, responses: { 200: { - description: "Returns predicted block date", + description: "Returns validators", content: { "application/json": { schema: z.array( diff --git a/api/src/services/db/providerStatusService.ts b/api/src/services/db/providerStatusService.ts index 53b239c42..4f0bbc1ff 100644 --- a/api/src/services/db/providerStatusService.ts +++ b/api/src/services/db/providerStatusService.ts @@ -81,6 +81,7 @@ export const getProviderDetail = async (address: string): Promise