@devkong/cli 0.0.67-alpha.5 → 0.0.67-alpha.7

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.
package/index.js CHANGED
@@ -63432,7 +63432,7 @@ var PublishVersionCommand = class {
63432
63432
 
63433
63433
  // packages/kong-cli/src/common/deployment.ts
63434
63434
  var DEPLOY_SUCCESS_ACTIONS = /* @__PURE__ */ new Set(["deployment completed"]);
63435
- var DEPLOY_FAILURE_ACTIONS = /* @__PURE__ */ new Set(["deployment failed", "save deployment details"]);
63435
+ var DEPLOY_FAILURE_ACTIONS = /* @__PURE__ */ new Set(["deployment failed"]);
63436
63436
  function isFailureEvent(event) {
63437
63437
  return event.eventType === "error" || DEPLOY_FAILURE_ACTIONS.has(event.action);
63438
63438
  }
@@ -63520,6 +63520,25 @@ function validateName(value) {
63520
63520
  );
63521
63521
  }
63522
63522
  }
63523
+ var DEPLOY_STEPS = [
63524
+ "create deployment",
63525
+ "health check",
63526
+ "save deployment details",
63527
+ "deployment completed"
63528
+ ];
63529
+ function createDeploySteps() {
63530
+ return DEPLOY_STEPS.map((action) => {
63531
+ const handlers = {
63532
+ resolve: () => void 0,
63533
+ reject: () => void 0
63534
+ };
63535
+ const done = new Promise((resolve2, reject) => {
63536
+ handlers.resolve = resolve2;
63537
+ handlers.reject = reject;
63538
+ });
63539
+ return { action, done, settle: (error) => error ? handlers.reject(error) : handlers.resolve() };
63540
+ });
63541
+ }
63523
63542
  var SetAliasCommand = class {
63524
63543
  constructor(profile) {
63525
63544
  this.profile = profile;
@@ -63530,6 +63549,7 @@ var SetAliasCommand = class {
63530
63549
  async execute(aliasName, extensionVersion, timeoutSeconds) {
63531
63550
  validateName(aliasName);
63532
63551
  const startedAt = utcNow(DEFAULT_TIMEZONE);
63552
+ const steps = createDeploySteps();
63533
63553
  await new Listr(
63534
63554
  [
63535
63555
  {
@@ -63577,41 +63597,12 @@ var SetAliasCommand = class {
63577
63597
  };
63578
63598
  await this.publicClient.assignExtensionAlias(ctx.kongJson.id, alias);
63579
63599
  task.output = joinUrlAndPath(this.profile.kongBaseUrl, "/extensions/aliases");
63600
+ this.pollDeploymentSteps(steps, ctx.kongJson.id, aliasName, startedAt, timeoutSeconds);
63580
63601
  },
63581
63602
  rendererOptions: { persistentOutput: true }
63582
63603
  },
63583
- {
63584
- title: "Wait for deployment",
63585
- task: async (ctx, task) => {
63586
- let stopped = false;
63587
- const result = await pollDeployment(this.managementClient, {
63588
- objectType: "EXTENSION_ALIAS",
63589
- basedOnId: ctx.kongJson.id,
63590
- aliasName,
63591
- createdAfter: startedAt,
63592
- timeoutSeconds,
63593
- onProgress: (progress) => {
63594
- if (stopped) {
63595
- return;
63596
- }
63597
- const latest = progress.events[0];
63598
- if (latest) {
63599
- task.output = `${latest.eventType === "error" ? "\u2717" : "\u2713"} ${latest.action}`;
63600
- }
63601
- if (progress.status === "failed") {
63602
- stopped = true;
63603
- }
63604
- }
63605
- });
63606
- if (result.status === "failed") {
63607
- throw new AppError(deploymentErrorMessage(result.events));
63608
- }
63609
- if (result.timedOut) {
63610
- task.output = `Still deploying after ${result.waitedSeconds}s \u2014 check the UI for completion.`;
63611
- }
63612
- },
63613
- rendererOptions: { persistentOutput: true }
63614
- }
63604
+ // Known deployment steps as a checklist; each ticks off on its event.
63605
+ ...steps.map((step) => ({ title: step.action, task: () => step.done }))
63615
63606
  ],
63616
63607
  {
63617
63608
  renderer: "default",
@@ -63623,6 +63614,47 @@ var SetAliasCommand = class {
63623
63614
  }
63624
63615
  ).run();
63625
63616
  }
63617
+ /**
63618
+ * Poll the deployment audit log and settle one step per matching event. Runs
63619
+ * detached from the task list; it settles a step as its event arrives and
63620
+ * fails the rest on a failed/timed-out deployment, stopping on the failed or
63621
+ * "deployment completed" event (poll terminal).
63622
+ */
63623
+ pollDeploymentSteps(steps, basedOnId, aliasName, createdAfter, timeoutSeconds) {
63624
+ const pending = new Map(steps.map((step) => [step.action, step]));
63625
+ const seen = /* @__PURE__ */ new Set();
63626
+ void pollDeployment(this.managementClient, {
63627
+ objectType: "EXTENSION_ALIAS",
63628
+ basedOnId,
63629
+ aliasName,
63630
+ createdAfter,
63631
+ timeoutSeconds,
63632
+ onProgress: (progress) => {
63633
+ for (const event of [...progress.events].reverse()) {
63634
+ if (seen.has(event.action)) {
63635
+ continue;
63636
+ }
63637
+ seen.add(event.action);
63638
+ pending.get(event.action)?.settle();
63639
+ }
63640
+ }
63641
+ }).then((result) => {
63642
+ if (result.status === "failed") {
63643
+ const error = new AppError(deploymentErrorMessage(result.events));
63644
+ steps.forEach((step) => step.settle(error));
63645
+ } else if (result.timedOut) {
63646
+ const error = new AppError(
63647
+ `Still deploying after ${result.waitedSeconds}s \u2014 check the UI for completion.`
63648
+ );
63649
+ steps.forEach((step) => step.settle(error));
63650
+ } else {
63651
+ steps.forEach((step) => step.settle());
63652
+ }
63653
+ }).catch((error) => {
63654
+ const wrapped = error instanceof Error ? error : new AppError(String(error));
63655
+ steps.forEach((step) => step.settle(wrapped));
63656
+ });
63657
+ }
63626
63658
  };
63627
63659
 
63628
63660
  // packages/kong-cli/src/common/cli.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devkong/cli",
3
- "version": "0.0.67-alpha.5",
3
+ "version": "0.0.67-alpha.7",
4
4
  "type": "commonjs",
5
5
  "main": "./index.js",
6
6
  "typings": "./index.d.ts",
@@ -5,4 +5,11 @@ export declare class SetAliasCommand {
5
5
  private managementClient;
6
6
  constructor(profile: Profile);
7
7
  execute(aliasName: string, extensionVersion: number, timeoutSeconds: number): Promise<void>;
8
+ /**
9
+ * Poll the deployment audit log and settle one step per matching event. Runs
10
+ * detached from the task list; it settles a step as its event arrives and
11
+ * fails the rest on a failed/timed-out deployment, stopping on the failed or
12
+ * "deployment completed" event (poll terminal).
13
+ */
14
+ private pollDeploymentSteps;
8
15
  }