@tailor-platform/sdk 0.14.3 → 0.15.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { WORKFLOW_JOB_BRAND, getDistDir, tailorUserMap } from "./job-BGBMNqRW.mjs";
1
+ import { WORKFLOW_JOB_BRAND, getDistDir, tailorUserMap } from "./job-Dx7eROGy.mjs";
2
2
  import Module, { createRequire } from "node:module";
3
3
  import { defineCommand } from "citty";
4
4
  import * as path$1 from "node:path";
@@ -149472,21 +149472,24 @@ async function workflowStart(options) {
149472
149472
  namespace: application.authNamespace,
149473
149473
  machineUserName: options.machineUser
149474
149474
  });
149475
+ const arg = options.arg === void 0 ? void 0 : typeof options.arg === "string" ? options.arg : JSON.stringify(options.arg);
149475
149476
  const { executionId } = await client.testStartWorkflow({
149476
149477
  workspaceId,
149477
149478
  workflowId,
149478
149479
  authInvoker,
149479
- arg: options.arg
149480
+ arg
149480
149481
  });
149481
- if (!options.wait) return { executionId };
149482
- return await waitForExecution({
149483
- client,
149484
- workspaceId,
149482
+ return {
149485
149483
  executionId,
149486
- interval: options.interval ?? 3e3,
149487
- format: options.format,
149488
- trackJobs: true
149489
- });
149484
+ wait: () => waitForExecution({
149485
+ client,
149486
+ workspaceId,
149487
+ executionId,
149488
+ interval: options.interval ?? 3e3,
149489
+ format: "json",
149490
+ trackJobs: true
149491
+ })
149492
+ };
149490
149493
  } catch (error) {
149491
149494
  if (error instanceof ConnectError && error.code === Code.NotFound) throw new Error(`Workflow '${options.nameOrId}' not found.`);
149492
149495
  throw error;
@@ -149546,18 +149549,20 @@ const startCommand = defineCommand({
149546
149549
  run: withCommonArgs(async (args) => {
149547
149550
  const format$2 = parseFormat(args.format);
149548
149551
  const interval = parseDuration(args.interval);
149549
- const result = await workflowStart({
149552
+ const { executionId, wait } = await workflowStart({
149550
149553
  nameOrId: args.nameOrId,
149551
149554
  machineUser: args.machineuser,
149552
149555
  arg: args.arg,
149553
149556
  workspaceId: args["workspace-id"],
149554
149557
  profile: args.profile,
149555
149558
  configPath: args.config,
149556
- wait: args.wait,
149557
- interval,
149558
- format: format$2
149559
+ interval
149559
149560
  });
149560
- printWithFormat(result, format$2);
149561
+ if (format$2 !== "json") consola.info(`Execution ID: ${executionId}`);
149562
+ if (args.wait) {
149563
+ const result = await wait();
149564
+ printWithFormat(result, format$2);
149565
+ } else printWithFormat({ executionId }, format$2);
149561
149566
  })
149562
149567
  });
149563
149568
 
@@ -149681,45 +149686,22 @@ async function workflowExecutionGet(options) {
149681
149686
  }));
149682
149687
  return result;
149683
149688
  }
149684
- try {
149685
- if (!options.wait) return await fetchExecutionWithLogs(options.executionId, options.logs ?? false);
149689
+ async function waitForCompletion() {
149686
149690
  const interval = options.interval ?? 3e3;
149687
- let lastStatus;
149688
- const spinner = ora().start("Waiting...");
149689
- try {
149690
- while (true) {
149691
- const { execution } = await client.getWorkflowExecution({
149692
- workspaceId,
149693
- executionId: options.executionId
149694
- });
149695
- if (!execution) {
149696
- spinner.fail(`Execution '${options.executionId}' not found.`);
149697
- throw new Error(`Execution '${options.executionId}' not found.`);
149698
- }
149699
- const now = formatTime(/* @__PURE__ */ new Date());
149700
- const coloredStatus = colorizeStatus(execution.status);
149701
- if (execution.status !== lastStatus) {
149702
- spinner.stop();
149703
- consola.info(`Status: ${coloredStatus}`);
149704
- spinner.start(`Polling...`);
149705
- lastStatus = execution.status;
149706
- }
149707
- spinner.text = `Polling... (${now})`;
149708
- if (execution.status === WorkflowExecution_Status.SUCCESS || execution.status === WorkflowExecution_Status.FAILED) {
149709
- if (execution.status === WorkflowExecution_Status.SUCCESS) spinner.succeed(`Completed: ${coloredStatus}`);
149710
- else spinner.fail(`Completed: ${coloredStatus}`);
149711
- return await fetchExecutionWithLogs(options.executionId, options.logs ?? false);
149712
- }
149713
- await sleep(interval);
149714
- }
149715
- } catch (error) {
149716
- spinner.stop();
149717
- throw error;
149691
+ while (true) {
149692
+ const { execution } = await client.getWorkflowExecution({
149693
+ workspaceId,
149694
+ executionId: options.executionId
149695
+ });
149696
+ if (!execution) throw new Error(`Execution '${options.executionId}' not found.`);
149697
+ if (execution.status === WorkflowExecution_Status.SUCCESS || execution.status === WorkflowExecution_Status.FAILED) return await fetchExecutionWithLogs(options.executionId, options.logs ?? false);
149698
+ await sleep(interval);
149718
149699
  }
149719
- } catch (error) {
149720
- if (error instanceof ConnectError && error.code === Code.NotFound) throw new Error(`Execution '${options.executionId}' not found.`);
149721
- throw error;
149722
149700
  }
149701
+ return {
149702
+ execution: await fetchExecutionWithLogs(options.executionId, options.logs ?? false),
149703
+ wait: waitForCompletion
149704
+ };
149723
149705
  }
149724
149706
  function parseDuration$1(duration) {
149725
149707
  const match = duration.match(/^(\d+)(s|ms|m)$/);
@@ -149733,6 +149715,22 @@ function parseDuration$1(duration) {
149733
149715
  default: throw new Error(`Unknown duration unit: ${unit}`);
149734
149716
  }
149735
149717
  }
149718
+ async function waitWithSpinner(waitFn, interval, format$2) {
149719
+ const spinner = format$2 !== "json" ? ora().start("Waiting...") : null;
149720
+ const updateInterval = setInterval(() => {
149721
+ if (spinner) spinner.text = `Polling... (${formatTime(/* @__PURE__ */ new Date())})`;
149722
+ }, interval);
149723
+ try {
149724
+ const result = await waitFn();
149725
+ const coloredStatus = colorizeStatus(WorkflowExecution_Status[result.status]);
149726
+ if (result.status === "SUCCESS") spinner?.succeed(`Completed: ${coloredStatus}`);
149727
+ else spinner?.fail(`Completed: ${coloredStatus}`);
149728
+ return result;
149729
+ } finally {
149730
+ clearInterval(updateInterval);
149731
+ spinner?.stop();
149732
+ }
149733
+ }
149736
149734
  function printExecutionWithLogs(execution) {
149737
149735
  const summaryData = [
149738
149736
  ["id", execution.id],
@@ -149820,16 +149818,17 @@ const executionsCommand = defineCommand({
149820
149818
  const format$2 = parseFormat(args.format);
149821
149819
  if (args.executionId) {
149822
149820
  const interval = parseDuration$1(args.interval);
149823
- const execution = await workflowExecutionGet({
149821
+ const { execution, wait } = await workflowExecutionGet({
149824
149822
  executionId: args.executionId,
149825
149823
  workspaceId: args["workspace-id"],
149826
149824
  profile: args.profile,
149827
- wait: args.wait,
149828
149825
  interval,
149829
149826
  logs: args.logs
149830
149827
  });
149831
- if (args.logs && format$2 === "table") printExecutionWithLogs(execution);
149832
- else printWithFormat(execution, format$2);
149828
+ if (format$2 !== "json") consola.info(`Execution ID: ${execution.id}`);
149829
+ const result = args.wait ? await waitWithSpinner(wait, interval, format$2) : execution;
149830
+ if (args.logs && format$2 === "table") printExecutionWithLogs(result);
149831
+ else printWithFormat(result, format$2);
149833
149832
  } else {
149834
149833
  const executions = await workflowExecutionsList({
149835
149834
  workspaceId: args["workspace-id"],
@@ -149859,14 +149858,16 @@ async function workflowResume(options) {
149859
149858
  workspaceId,
149860
149859
  executionId: options.executionId
149861
149860
  });
149862
- if (!options.wait) return { executionId };
149863
- return await waitForExecution({
149864
- client,
149865
- workspaceId,
149861
+ return {
149866
149862
  executionId,
149867
- interval: options.interval ?? 3e3,
149868
- format: options.format
149869
- });
149863
+ wait: () => waitForExecution({
149864
+ client,
149865
+ workspaceId,
149866
+ executionId,
149867
+ interval: options.interval ?? 3e3,
149868
+ format: "json"
149869
+ })
149870
+ };
149870
149871
  } catch (error) {
149871
149872
  if (error instanceof ConnectError) {
149872
149873
  if (error.code === Code.NotFound) throw new Error(`Execution '${options.executionId}' not found.`);
@@ -149912,18 +149913,23 @@ const resumeCommand = defineCommand({
149912
149913
  run: withCommonArgs(async (args) => {
149913
149914
  const format$2 = parseFormat(args.format);
149914
149915
  const interval = parseDuration(args.interval);
149915
- const result = await workflowResume({
149916
+ const { executionId, wait } = await workflowResume({
149916
149917
  executionId: args.executionId,
149917
149918
  workspaceId: args["workspace-id"],
149918
149919
  profile: args.profile,
149919
- wait: args.wait,
149920
- interval,
149921
- format: format$2
149920
+ interval
149922
149921
  });
149923
- printWithFormat(result, format$2);
149922
+ if (format$2 !== "json") {
149923
+ const { default: consola$2 } = await import("consola");
149924
+ consola$2.info(`Execution ID: ${executionId}`);
149925
+ }
149926
+ if (args.wait) {
149927
+ const result = await wait();
149928
+ printWithFormat(result, format$2);
149929
+ } else printWithFormat({ executionId }, format$2);
149924
149930
  })
149925
149931
  });
149926
149932
 
149927
149933
  //#endregion
149928
149934
  export { PATScope, apply, applyCommand, commonArgs, createCommand, deleteCommand, executionsCommand, fetchAll, fetchLatestToken, fetchUserInfo, formatArgs, generate, generateCommand, generateUserTypes, getCommand, getCommand$1, initOAuth2Client, initOperatorClient, listCommand, listCommand$1, listCommand$2, listCommand$3, loadAccessToken, loadConfig, loadWorkspaceId, machineUserList, machineUserToken, oauth2ClientGet, oauth2ClientList, parseFormat, printWithFormat, readPackageJson, readPlatformConfig, remove, removeCommand, resumeCommand, show, showCommand, startCommand, tokenCommand, withCommonArgs, workflowExecutionGet, workflowExecutionsList, workflowGet, workflowList, workflowResume, workflowStart, workspaceCreate, workspaceDelete, workspaceList, writePlatformConfig };
149929
- //# sourceMappingURL=resume-CVNNM93m.mjs.map
149935
+ //# sourceMappingURL=resume-DJfAvxVb.mjs.map