Skip to content
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
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "https://deno.land/x/deno/cli/schemas/config-file.v1.json",
"name": "@flowcore/sdk",
"description": "Flowcore SDK",
"version": "1.70.0",
"version": "1.71.0",
"license": "MIT",
"exports": "./src/mod.ts",
"publish": {
Expand Down
26 changes: 26 additions & 0 deletions src/commands/data-pathways/health.check.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Command } from "../../common/command.ts"
import { type DataPathwayHealth, DataPathwayHealthSchema } from "../../contracts/data-pathways.ts"
import { parseResponseHelper } from "../../utils/parse-response-helper.ts"

export type DataPathwayHealthCheckInput = Record<string, never>

export class DataPathwayHealthCheckCommand extends Command<DataPathwayHealthCheckInput, DataPathwayHealth> {
protected override retryOnFailure: boolean = false
protected override allowedModes: ("apiKey" | "bearer")[] = ["bearer"]

protected override getMethod(): string {
return "GET"
}

protected override getBaseUrl(): string {
return "https://data-pathways.api.flowcore.io"
}

protected override getPath(): string {
return "/api/v1/health"
}

protected override parseResponse(rawResponse: unknown): DataPathwayHealth {
return parseResponseHelper(DataPathwayHealthSchema, rawResponse)
}
}
4 changes: 4 additions & 0 deletions src/commands/data-pathways/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export * from "./pathway.create.ts"
export * from "./pathway.fetch.ts"
export * from "./pathway.list.ts"
export * from "./pathway.disable.ts"
export * from "./pathway.delete.ts"

// Slots
export * from "./slot.register.ts"
Expand Down Expand Up @@ -40,3 +41,6 @@ export * from "./quota.list.ts"
// Pump State
export * from "./pump-state.fetch.ts"
export * from "./pump-state.save.ts"

// Health
export * from "./health.check.ts"
43 changes: 43 additions & 0 deletions src/commands/data-pathways/pathway.delete.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Command } from "../../common/command.ts"
import { type DataPathwayMutationResponse, DataPathwayMutationResponseSchema } from "../../contracts/data-pathways.ts"
import type { ClientError } from "../../exceptions/client-error.ts"
import { NotFoundException } from "../../exceptions/not-found.ts"
import { parseResponseHelper } from "../../utils/parse-response-helper.ts"

export interface DataPathwayDeleteInput {
id: string
reason?: string
}

export class DataPathwayDeleteCommand extends Command<DataPathwayDeleteInput, DataPathwayMutationResponse> {
protected override retryOnFailure: boolean = false
protected override allowedModes: ("apiKey" | "bearer")[] = ["bearer"]

protected override getMethod(): string {
return "DELETE"
}

protected override getBaseUrl(): string {
return "https://data-pathways.api.flowcore.io"
}

protected override getPath(): string {
return `/api/v1/pathways/${this.input.id}`
}

protected override getBody(): Record<string, unknown> {
const { id: _id, ...payload } = this.input
return payload
}

protected override parseResponse(rawResponse: unknown): DataPathwayMutationResponse {
return parseResponseHelper(DataPathwayMutationResponseSchema, rawResponse)
}

protected override handleClientError(error: ClientError): void {
if (error.status === 404) {
throw new NotFoundException("DataPathway", { id: this.input.id })
}
throw error
}
}
13 changes: 13 additions & 0 deletions src/contracts/data-pathways.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,3 +455,16 @@ export const DataPathwayPumpStateSaveResponseSchema: TObject<{
status: Type.String(),
})
export type DataPathwayPumpStateSaveResponse = Static<typeof DataPathwayPumpStateSaveResponseSchema>

// ── Health ──

export const DataPathwayHealthSchema: TObject<{
status: TUnion<[TLiteral<"healthy">, TLiteral<"unhealthy">]>
checks: TObject<{ db: TUnion<[TLiteral<"ok">, TLiteral<"error">]> }>
uptime: TNumber
}> = Type.Object({
status: Type.Union([Type.Literal("healthy"), Type.Literal("unhealthy")]),
checks: Type.Object({ db: Type.Union([Type.Literal("ok"), Type.Literal("error")]) }),
uptime: Type.Number(),
})
export type DataPathwayHealth = Static<typeof DataPathwayHealthSchema>
Loading