chore: Workflow execution JS-SDK (#8851)

This commit is contained in:
Oli Juhl
2024-08-29 11:22:43 +00:00
committed by GitHub
parent e396c01260
commit 00bd9271e3
19 changed files with 192 additions and 178 deletions
+3
View File
@@ -37,6 +37,7 @@ import { TaxRate } from "./tax-rate"
import { TaxRegion } from "./tax-region"
import { Upload } from "./upload"
import { User } from "./user"
import { WorkflowExecution } from "./workflow-execution"
export class Admin {
public invite: Invite
@@ -75,6 +76,7 @@ export class Admin {
public refundReason: RefundReason
public paymentCollection: PaymentCollection
public apiKey: ApiKey
public workflowExecution: WorkflowExecution
public reservation: Reservation
public customerGroup: CustomerGroup
@@ -115,6 +117,7 @@ export class Admin {
this.exchange = new Exchange(client)
this.paymentCollection = new PaymentCollection(client)
this.apiKey = new ApiKey(client)
this.workflowExecution = new WorkflowExecution(client)
this.reservation = new Reservation(client)
this.customerGroup = new CustomerGroup(client)
}
@@ -0,0 +1,32 @@
import { HttpTypes } from "@medusajs/types"
import { Client } from "../client"
import { ClientHeaders } from "../types"
export class WorkflowExecution {
private client: Client
constructor(client: Client) {
this.client = client
}
async list(
queryParams?: HttpTypes.AdminGetWorkflowExecutionsParams,
headers?: ClientHeaders
) {
return await this.client.fetch<HttpTypes.AdminWorkflowExecutionListResponse>(
`/admin/workflows-executions`,
{
query: queryParams,
headers,
}
)
}
async retrieve(id: string, headers?: ClientHeaders) {
return await this.client.fetch<HttpTypes.AdminWorkflowExecutionResponse>(
`/admin/workflows-executions/${id}`,
{
headers,
}
)
}
}
@@ -1,11 +1,92 @@
export type TransactionStepStatus =
| "idle"
| "ok"
| "waiting_response"
| "temp_failure"
| "permanent_failure"
export type TransactionState =
| "not_started"
| "invoking"
| "waiting_to_compensate"
| "compensating"
| "done"
| "reverted"
| "failed"
export type TransactionStepState =
| "not_started"
| "invoking"
| "compensating"
| "done"
| "reverted"
| "failed"
| "dormant"
| "skipped"
| "skipped_failure"
| "timeout"
interface AdminWorkflowExecutionExecution {
steps: Record<string, AdminWorkflowExecutionStep>
}
export type StepInvokeResult = {
output: {
output: unknown
compensateInput: unknown
}
}
export type StepError = {
error: Record<string, unknown>
action: string
handlerType: string
}
export interface WorkflowExecutionContext {
data: {
invoke: Record<string, StepInvokeResult>
payload?: unknown
}
compensate: Record<string, unknown>
errors: StepError[]
}
export interface WorkflowExecutionDefinition {
async?: boolean
compensateAsync?: boolean
noCompensation?: boolean
continueOnPermanentFailure?: boolean
maxRetries?: number
noWait?: boolean
retryInterval?: number
retryIntervalAwaiting?: number
saveResponse?: boolean
timeout?: number
}
export interface WorkflowExecutionFn {
state: TransactionStepState
status: TransactionStepStatus
}
export interface AdminWorkflowExecutionStep {
id: string
invoke: WorkflowExecutionFn
definition: WorkflowExecutionDefinition
compensate: WorkflowExecutionFn
depth: number
startedAt: number
}
export interface AdminWorkflowExecution {
id: string
workflow_id: string
transaction_id: string
execution: string
context: string
state: any
execution: AdminWorkflowExecutionExecution
context: WorkflowExecutionContext
state: TransactionState
created_at: Date
updated_at: Date
deleted_at: Date
}
deleted_at?: Date | null
}
@@ -1,2 +1,3 @@
export * from "./entities"
export * from "./responses"
export * from "./queries"
export * from "./responses"
@@ -0,0 +1,6 @@
import { FindParams } from "../../common"
export interface AdminGetWorkflowExecutionsParams extends FindParams {
transaction_id?: string | string[]
workflow_id?: string | string[]
}
@@ -1,5 +1,5 @@
import { PaginatedResponse } from "../../common/response";
import { AdminWorkflowExecution } from "./entities";
import { PaginatedResponse } from "../../common/response"
import { AdminWorkflowExecution } from "./entities"
export interface AdminWorkflowExecutionResponse {
workflow_execution: AdminWorkflowExecution
@@ -7,4 +7,4 @@ export interface AdminWorkflowExecutionResponse {
export type AdminWorkflowExecutionListResponse = PaginatedResponse<{
workflow_executions: AdminWorkflowExecution[]
}>
}>