File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ import { ContextHelpers } from "./lib/types"
1818import { version } from "./package.json"
1919import { interactForUseRemoteApiDefs } from "./lib/interact-for-use-remote-api-defs"
2020import { randomBytes } from "node:crypto"
21+ import { interactForActionAttemptPoll } from "./lib/interact-for-action-attempt-poll"
2122
2223const sections = [
2324 {
@@ -245,23 +246,12 @@ async function cli(args: ParsedArgs) {
245246 }
246247 }
247248
248- if ( "action_attempt" in response . data ) {
249- const { poll_for_action_attempt } = await prompts ( {
250- name : "poll_for_action_attempt" ,
251- message : "Would you like to poll the action attempt until it's ready?" ,
252- type : "toggle" ,
253- initial : true ,
254- active : "yes" ,
255- inactive : "no" ,
256- } )
257-
258- if ( poll_for_action_attempt ) {
259- const { action_attempt_id } = response . data . action_attempt
260- await seam . actionAttempts . get (
261- { action_attempt_id } ,
262- { waitForActionAttempt : { pollingInterval : 240 , timeout : 10_000 } }
263- )
264- }
249+ if (
250+ response . data &&
251+ typeof response . data === "object" &&
252+ "action_attempt" in response . data
253+ ) {
254+ interactForActionAttemptPoll ( response . data . action_attempt )
265255 }
266256}
267257
Original file line number Diff line number Diff line change 1+ import prompts from "prompts"
2+ import { getSeam } from "./get-seam"
3+ import { ActionAttemptsGetResponse } from "@seamapi/http/connect"
4+
5+ export const interactForActionAttemptPoll = async (
6+ action_attempt : ActionAttemptsGetResponse [ "action_attempt" ]
7+ ) => {
8+ if ( action_attempt . status === "pending" ) {
9+ const { poll_for_action_attempt } = await prompts ( {
10+ name : "poll_for_action_attempt" ,
11+ message : "Would you like to poll the action attempt until it's ready?" ,
12+ type : "toggle" ,
13+ initial : true ,
14+ active : "yes" ,
15+ inactive : "no" ,
16+ } )
17+
18+ if ( poll_for_action_attempt ) {
19+ const seam = await getSeam ( )
20+ const { action_attempt_id } = action_attempt
21+
22+ const updated_action_attempt = await seam . actionAttempts . get (
23+ { action_attempt_id } ,
24+ { waitForActionAttempt : { pollingInterval : 240 , timeout : 10_000 } }
25+ )
26+
27+ console . dir ( updated_action_attempt , { depth : null } )
28+ }
29+ }
30+ }
You can’t perform that action at this time.
0 commit comments