1 import { HttpTypes } from "@medusajs/types"
2 import { Client } from "../client.js"
3 import { ClientHeaders } from "../types.js"
4
5 export class WorkflowExecution {
6 /**
7 * @ignore
8 */
9 private client: Client
10 /**
11 * @ignore
12 */
13 constructor(client: Client) {
14 this.client = client
15 }
16
17 /**
18 * This method retrieves a list of workflow executions. It sends a request to the
19 * [List Workflow Executions](https://docs.medusajs.com/api/admin/workflows-executions/list-workflows-executions)
20 * API route.
21 *
22 * @param queryParams - Filters and pagination configurations.
23 * @param headers - Headers to pass in the request.
24 * @returns The list of workflow executions.
25 *
26 * @example
27 * To retrieve the list of workflow executions:
28 *
29 * ```ts
30 * sdk.admin.workflowExecution.list()
31 * .then(({ workflow_executions, count, limit, offset }) => {
32 * console.log(workflow_executions)
33 * })
34 * ```
35 *
36 * To configure the pagination, pass the `limit` and `offset` query parameters.
37 *
38 * For example, to retrieve only 10 items and skip 10 items:
39 *
40 * ```ts
41 * sdk.admin.workflowExecution.list({
42 * limit: 10,
43 * offset: 10
44 * })
45 * .then(({ workflow_executions, count, limit, offset }) => {
46 * console.log(workflow_executions)
47 * })
48 * ```
49 *
50 * Using the `fields` query parameter, you can specify the fields and relations to retrieve
51 * in each workflow execution:
52 *
53 * ```ts
54 * sdk.admin.workflowExecution.list({
55 * fields: "id,name"
56 * })
57 * .then(({ workflow_executions, count, limit, offset }) => {
58 * console.log(workflow_executions)
59 * })
60 * ```
61 *
62 * Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/api/admin/select-fields-and-relations).
63 */
64 async list(
65 queryParams?: HttpTypes.AdminGetWorkflowExecutionsParams,
66 headers?: ClientHeaders
67 ) {
68 return await this.client.fetch<HttpTypes.AdminWorkflowExecutionListResponse>(
69 `/admin/workflows-executions`,
70 {
71 query: queryParams,
72 headers,
73 }
74 )
75 }
76
77 /**
78 * This method retrieves a workflow execution by its ID. It sends a request to the
79 * [Get Workflow Execution](https://docs.medusajs.com/api/admin/workflows-executions/get-exection)
80 * API route.
81 *
82 * @param id - The ID of the workflow execution to retrieve.
83 * @param headers - Headers to pass in the request.
84 * @returns The workflow execution's details.
85 *
86 * @example
87 * sdk.admin.workflowExecution.retrieve("wrk_123")
88 * .then(({ workflow_execution }) => {
89 * console.log(workflow_execution)
90 * })
91 */
92 async retrieve(id: string, headers?: ClientHeaders) {
93 return await this.client.fetch<HttpTypes.AdminWorkflowExecutionResponse>(
94 `/admin/workflows-executions/${id}`,
95 {
96 headers,
97 }
98 )
99 }
100 }