Skip to content

Commit

Permalink
fix: expose command class + add v2 events commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Fjandin committed Nov 7, 2024
1 parent 8d82fa0 commit c3ac222
Show file tree
Hide file tree
Showing 7 changed files with 369 additions and 3 deletions.
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Flowcore SDK",
"version": "1.0.0",
"license": "MIT",
"exports": "./src/main.ts",
"exports": "./src/mod.ts",
"tasks": {},
"imports": {
"@sinclair/typebox": "npm:@sinclair/[email protected]",
Expand Down
131 changes: 129 additions & 2 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@ export * from "./event-type/event-type.list.ts"
// Events
export * from "./events/events.fetch.ts"
export * from "./events/events.fetch-indexes.ts"

// V2
export * from "./v2/events/events.fetch-time-buckets-by-name.ts"
export * from "./v2/events/events.fetch-time-buckets.ts"
export * from "./v2/events/events.fetch.ts"
78 changes: 78 additions & 0 deletions src/commands/v2/events/events.fetch-time-buckets-by-name.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { Type } from "@sinclair/typebox"
import { Command } from "../../../common/command.ts"
import { parseResponseHelper } from "../../../utils/parse-response-helper.ts"

/**
* The input for the events fetch indexes command
*/
export interface V2EventsFetchTimeBucketsByNameInput {
/** the tenant name */
tenant: string
/** the data core id */
dataCoreId: string
/** the flow type name */
flowType: string
/** the event type name */
eventType: string
/** the paging cursor */
cursor?: number
/** the page size (default is 10.000) */
pageSize?: number
/** start from this time bucket */
fromTimeBucket?: string
/** end at this time bucket */
toTimeBucket?: string
}

/**
* The output for the events fetch indexes command
*/
export interface V2EventsFetchTimeBucketsByNameOutput {
/** the time buckets */
timeBuckets: string[]
/** the next page cursor */
nextCursor?: string
}

const responseSchema = Type.Object({
timeBuckets: Type.Array(Type.String()),
nextCursor: Type.Optional(Type.String()),
})

/**
* Fetch time buckets for an event type
*/
export class V2EventsFetchTimeBucketsByNameCommand
extends Command<V2EventsFetchTimeBucketsByNameInput, V2EventsFetchTimeBucketsByNameOutput> {
/**
* Get the base url for the request
*/
protected override getBaseUrl(): string {
return "https://event-source.api.flowcore.io"
}
/**
* Get the path for the request
*/
protected override getPath(): string {
return `/api/v1/time-buckets/byName/${this.input.tenant}/${this.input.dataCoreId}/${this.input.flowType}/${this.input.eventType}`
}
/**
* Parse the response
*/
protected override parseResponse(rawResponse: unknown): V2EventsFetchTimeBucketsByNameOutput {
const response = parseResponseHelper(responseSchema, rawResponse)
return response
}

/**
* Get the body for the request
*/
protected override getBody(): string {
return JSON.stringify({
cursor: this.input.cursor,
pageSize: this.input.pageSize,
fromTimeBucket: this.input.fromTimeBucket,
toTimeBucket: this.input.toTimeBucket,
})
}
}
78 changes: 78 additions & 0 deletions src/commands/v2/events/events.fetch-time-buckets.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { Type } from "@sinclair/typebox"
import { Command } from "../../../common/command.ts"
import { parseResponseHelper } from "../../../utils/parse-response-helper.ts"

/**
* The input for the events fetch indexes command
*/
export interface V2EventsFetchTimeBucketsInput {
/** the tenant id */
tenantId: string
/** the data core id */
dataCoreId: string
/** the flow type id */
flowTypeId: string
/** the event type id */
eventTypeId: string
/** the paging cursor */
cursor?: number
/** the page size (default is 10.000) */
pageSize?: number
/** start from this time bucket */
fromTimeBucket?: string
/** end at this time bucket */
toTimeBucket?: string
}

/**
* The output for the events fetch indexes command
*/
export interface V2EventsFetchTimeBucketsOutput {
/** the time buckets */
timeBuckets: string[]
/** the next page cursor */
nextCursor?: string
}

const responseSchema = Type.Object({
timeBuckets: Type.Array(Type.String()),
nextCursor: Type.Optional(Type.String()),
})

/**
* Fetch time buckets for an event type
*/
export class V2EventsFetchTimeBucketsCommand
extends Command<V2EventsFetchTimeBucketsInput, V2EventsFetchTimeBucketsOutput> {
/**
* Get the base url for the request
*/
protected override getBaseUrl(): string {
return "https://event-source.api.flowcore.io"
}
/**
* Get the path for the request
*/
protected override getPath(): string {
return `/api/v1/time-buckets/byId/${this.input.tenantId}/${this.input.dataCoreId}/${this.input.flowTypeId}/${this.input.eventTypeId}`
}
/**
* Parse the response
*/
protected override parseResponse(rawResponse: unknown): V2EventsFetchTimeBucketsOutput {
const response = parseResponseHelper(responseSchema, rawResponse)
return response
}

/**
* Get the body for the request
*/
protected override getBody(): string {
return JSON.stringify({
cursor: this.input.cursor,
pageSize: this.input.pageSize,
fromTimeBucket: this.input.fromTimeBucket,
toTimeBucket: this.input.toTimeBucket,
})
}
}
Loading

0 comments on commit c3ac222

Please sign in to comment.