-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: expose command class + add v2 events commands
- Loading branch information
Showing
7 changed files
with
369 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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]", | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
src/commands/v2/events/events.fetch-time-buckets-by-name.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}) | ||
} | ||
} |
Oops, something went wrong.