Openstatus www.openstatus.dev

✏️ typo api (#1267)

* ✏️ typo api

* 🥰

* 🚀

* ci: apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>

authored by

Thibault Le Ouay
autofix-ci[bot]
and committed by
GitHub
0a20224d 6472c09d

+107 -8
+4 -4
apps/server/src/routes/v1/monitors/post_http.test.ts
··· 25 25 public: true, 26 26 assertions: [ 27 27 { 28 - type: "status", 28 + kind: "statusCode", 29 29 compare: "eq", 30 30 target: 200, 31 31 }, 32 - { type: "header", compare: "not_eq", key: "key", target: "value" }, 32 + { kind: "header", compare: "not_eq", key: "key", target: "value" }, 33 33 ], 34 34 }), 35 35 }); ··· 62 62 public: true, 63 63 assertions: [ 64 64 { 65 - type: "status", 65 + kind: "status", 66 66 compare: "eq", 67 67 target: 200, 68 68 }, 69 - { type: "header", compare: "not_eq", key: "key", target: "value" }, 69 + { kind: "header", compare: "not_eq", key: "key", target: "value" }, 70 70 ], 71 71 }), 72 72 });
+2 -2
apps/server/src/routes/v1/monitors/post_http.ts
··· 10 10 import { trackMiddleware } from "@/libs/middlewares"; 11 11 import type { monitorsApi } from "./index"; 12 12 import { HTTPMonitorSchema, MonitorSchema } from "./schema"; 13 - import { getAssertions } from "./utils"; 13 + import { getAssertionNew, getAssertions } from "./utils"; 14 14 15 15 const postRoute = createRoute({ 16 16 method: "post", ··· 94 94 const headersEntries = headers 95 95 ? headers.map(([key, value]) => ({ key: key, value: value })) 96 96 : undefined; 97 - const assert = assertions ? getAssertions(assertions) : []; 97 + const assert = assertions ? getAssertionNew(assertions) : []; 98 98 99 99 const _newMonitor = await db 100 100 .insert(monitor)
+67 -1
apps/server/src/routes/v1/monitors/schema.ts
··· 378 378 }), 379 379 }); 380 380 381 + const statusCodeAssertion = z 382 + .object({ 383 + kind: z.literal("statusCode"), 384 + compare: numberCompare.openapi({ 385 + description: "Comparison operator", 386 + examples: ["eq", "not_eq", "gt", "gte", "lt", "lte"], 387 + }), 388 + target: z.number().openapi({ 389 + description: "Status code to assert", 390 + examples: [200, 404, 418, 500], 391 + }), 392 + }) 393 + .openapi({ 394 + examples: [ 395 + { 396 + kind: "statusCode", 397 + compare: "eq", 398 + target: 200, 399 + }, 400 + { 401 + kind: "statusCode", 402 + compare: "not_eq", 403 + target: 404, 404 + }, 405 + { 406 + kind: "statusCode", 407 + compare: "gt", 408 + target: 300, 409 + }, 410 + ], 411 + }); 412 + 413 + const headerAssertions = z.object({ 414 + kind: z.literal("header"), 415 + compare: stringCompare.openapi({ 416 + description: "Comparison operator", 417 + examples: ["eq", "not_eq", "contains", "not_contains"], 418 + }), 419 + key: z.string().openapi({ 420 + description: "Header key to assert", 421 + examples: ["Content-Type", "X-Request-ID"], 422 + }), 423 + target: z.string().openapi({ 424 + description: "Header value to assert", 425 + examples: ["application/json", "text/html"], 426 + }), 427 + }); 428 + 429 + const textBodyAssertions = z.object({ 430 + kind: z.literal("textBody"), 431 + compare: stringCompare.openapi({ 432 + description: "Comparison operator", 433 + examples: ["eq", "not_eq", "contains", "not_contains"], 434 + }), 435 + target: z.string().openapi({ 436 + description: "Text body to assert", 437 + examples: ["Hello, world!", "404 Not Found"], 438 + }), 439 + }); 440 + 441 + export const assertionsSchema = z.discriminatedUnion("kind", [ 442 + statusCodeAssertion, 443 + headerAssertions, 444 + textBodyAssertions, 445 + ]); 446 + 381 447 export const HTTPMonitorSchema = baseRequest.extend({ 382 - assertions: z.array(assertion).optional().openapi({ 448 + assertions: z.array(assertionsSchema).optional().openapi({ 383 449 description: "Assertions to run on the response", 384 450 }), 385 451 request: httpRequestSchema.openapi({
+34 -1
apps/server/src/routes/v1/monitors/utils.ts
··· 5 5 TextBodyAssertion, 6 6 } from "@openstatus/assertions"; 7 7 import type { z } from "zod"; 8 - import type { assertion } from "./schema"; 8 + import type { assertion, assertionsSchema } from "./schema"; 9 9 10 10 export const getAssertions = ( 11 11 assertions: z.infer<typeof assertion>[], ··· 25 25 } 26 26 return assert; 27 27 }; 28 + 29 + export const getAssertionNew = ( 30 + assertions: z.infer<typeof assertionsSchema>[], 31 + ): Assertion[] => { 32 + const assert: Assertion[] = []; 33 + 34 + for (const a of assertions) { 35 + if (a.kind === "header") { 36 + const { kind, ...rest } = a; 37 + assert.push( 38 + new HeaderAssertion({ 39 + ...rest, 40 + type: "header", 41 + version: "v1", 42 + }), 43 + ); 44 + } 45 + if (a.kind === "textBody") { 46 + const { kind, ...rest } = a; 47 + 48 + assert.push( 49 + new TextBodyAssertion({ ...rest, type: "textBody", version: "v1" }), 50 + ); 51 + } 52 + if (a.kind === "statusCode") { 53 + const { kind, ...rest } = a; 54 + assert.push( 55 + new StatusAssertion({ ...rest, type: "status", version: "v1" }), 56 + ); 57 + } 58 + } 59 + return assert; 60 + };