Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfixes/add missing redirects #98

Merged
merged 2 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,9 @@ Here is a list of endpoints that have changed in this release. Old endpoints wil

|Old|New|
|-|-
|`/predicted-block-date/<height>/<blockWindow>` | `/predicted-block-date/<height>?blockWindow=<blockWindow>`
|`/predicted-date-height/<timestamp>/<blockWindow>` | `/predicted-date-height/<timestamp>?blockWindow=<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`
Expand All @@ -70,4 +67,8 @@ Here is a list of endpoints that have changed in this release. Old endpoints wil
|`/getTestnetVersion`|`/version/testnet`
|`/getProviderGraphData/<dataName>`|`/provider-graph-data/<dataName>`
|`/getProviderActiveLeasesGraphData/<address>`|`/provider-active-leases-graph-data/<address>`
|`/getGraphData/<dataName>`|`/graph-data/<dataName>`
|`/getGraphData/<dataName>`|`/graph-data/<dataName>`
|`/marketData`|`/market-data`
|`/predicted-block-date/<height>/<blockWindow>` | `/predicted-block-date/<height>?blockWindow=<blockWindow>`
|`/predicted-date-height/<timestamp>/<blockWindow>` | `/predicted-date-height/<timestamp>?blockWindow=<blockWindow>`
|`/providers/<provider>/deployments/<skip>/<take>/<status>`|`/providers/<provider>/deployments/<skip>/<take>?status=<status>`
96 changes: 96 additions & 0 deletions api/src/routers/legacyRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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);
});
Expand All @@ -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);
});
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 5 additions & 3 deletions api/src/routes/v1/addresses/deployments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
Expand All @@ -19,15 +21,15 @@ const route = createRoute({
}),
limit: z.string().openapi({
description: "Deployments to return",
example: "10"
example: "10",
maximum: maxLimit
})
}),
query: z.object({
status: z
.string()
.optional()
.openapi({
param: { name: "status", in: "query" },
description: "Filter by status", // TODO: Set possible statuses?
example: "closed"
}),
Expand Down Expand Up @@ -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

Expand Down
8 changes: 5 additions & 3 deletions api/src/routes/v1/addresses/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
Expand All @@ -20,7 +22,8 @@ const route = createRoute({
}),
limit: z.string().openapi({
description: "Transactions to return",
example: "10"
example: "10",
maximum: maxLimit
})
})
},
Expand Down Expand Up @@ -69,15 +72,14 @@ 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);
}

if (isNaN(limit)) {
return c.text("Invalid limit.", 400);
return;
}

const txs = await getTransactionByAddress(c.req.valid("param").address, skip, limit);
Expand Down
2 changes: 1 addition & 1 deletion api/src/routes/v1/blocks/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
56 changes: 28 additions & 28 deletions api/src/routes/v1/providerAttributesSchema.ts
Original file line number Diff line number Diff line change
@@ -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(),
Expand All @@ -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
})
}
}
Expand Down
25 changes: 17 additions & 8 deletions api/src/routes/v1/providers/deployments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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: {
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion api/src/routes/v1/validators/byAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
3 changes: 1 addition & 2 deletions api/src/routes/v1/validators/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions api/src/services/db/providerStatusService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export const getProviderDetail = async (address: string): Promise<ProviderDetail
},
{
model: ProviderSnapshot,
as: "providerSnapshots",
attributes: ["isOnline", "id", "checkDate"],
required: false,
separate: true,
Expand Down
Loading