@diagonal-hq/cli 0.10.0 → 0.10.2

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/README.md CHANGED
@@ -7,7 +7,7 @@ This package is the authoring SDK for file-based workspaces. A workspace reposit
7
7
  - Editor types for the workflow script SDK: `@diagonal/workflow`, `@diagonal/workflow/testing`, and `@diagonal/workflow/workspace`.
8
8
  - The `diagonal check` command. It runs the same build and checks that a platform deploy runs, including the workflow tests. It also writes `generated/resources.ts` and the missing definition uids.
9
9
  - The `diagonal assets upload` and `diagonal assets list` commands. They upload Application Assets, update `assets.ts`, and list immutable references.
10
- - The `diagonal workflows` and `diagonal run` commands. They list the deployed workflows and run a manual workflow by its file path.
10
+ - The `diagonal workflows`, `diagonal run`, and `diagonal logs` commands. They list the deployed workflows, run a manual workflow by its file path, and print recent runs with the error of each failed run.
11
11
 
12
12
  ## Check a workspace
13
13
 
@@ -33,7 +33,7 @@ The API commands read `DIAGONAL_URL` and `DIAGONAL_API_KEY`. Workflow commands r
33
33
 
34
34
  ## Run a deployed workflow
35
35
 
36
- `diagonal workflows` and `diagonal run` call the runtime API of a deployed workspace. Set two environment variables first:
36
+ `diagonal workflows`, `diagonal run`, and `diagonal logs` call the runtime API of a deployed workspace. Set two environment variables first:
37
37
 
38
38
  - `DIAGONAL_URL` is the workspace URL, for example `https://acme.diagonal.app`.
39
39
  - `DIAGONAL_API_KEY` is an API key of an account with `manage_workflows`.
@@ -41,11 +41,14 @@ The API commands read `DIAGONAL_URL` and `DIAGONAL_API_KEY`. Workflow commands r
41
41
  ```text
42
42
  diagonal workflows [--json]
43
43
  diagonal run <path> [--input '<json object>'] [--json]
44
+ diagonal logs [path | execution id] [--status <status>] [--limit <1-100>] [--json]
44
45
  ```
45
46
 
46
47
  - `diagonal workflows` prints the path, the trigger type, and the title of each workflow of the active deployment. `--json` prints the API response, which also has each workflow id and version id.
47
48
  - `diagonal run workflows/seed-catalog.ts` runs the manual workflow at that path in the active deployment and waits for it. It prints the terminal status, the execution id, and the output. `--input` gives the workflow input as a JSON object. `--json` prints the API response.
48
49
 
50
+ - `diagonal logs` prints the recent runs of the deployed workflows, oldest first: the start time, the status and the response status, the path, the trigger, the duration, and the execution id. Under a failed run it prints the error type and message, and each field error. A path narrows the list to one workflow. `--status` takes `success`, `error` (a declared failure or an exception), `exception`, `started`, or `pending`. `--limit` sets the number of runs (default 20). `diagonal logs <execution id>` prints one run with its full error or its output. `--json` prints the API response.
51
+
49
52
  `diagonal run` exits with 0 when the run succeeds, with 1 when the request or the run fails, and with 2 for a usage error or a missing environment variable. A workflow that is not manual, or a path that the active deployment does not have, is a request failure.
50
53
 
51
54
  ## What the checks do
@@ -186,7 +189,10 @@ export default defineNotificationTemplate({
186
189
  email: {
187
190
  subject: 'Welcome to {{ workspace.name }}, {{ record.name }}',
188
191
  layout: 'standard',
189
- fields: { heading: 'Welcome aboard', body: { file: './standard.email.liquid' } }
192
+ fields: {
193
+ heading: 'Welcome aboard',
194
+ body: { file: './standard.email.liquid' }
195
+ }
190
196
  },
191
197
  sms: { body: { file: './standard.sms.liquid' } },
192
198
  references: {
package/dist/cli.mjs CHANGED
@@ -249236,7 +249236,10 @@ import { resolve as resolve5 } from "node:path";
249236
249236
  init_define_globalThis_DIAGONAL_SDK_RUNTIME();
249237
249237
  var WORKFLOWS_USAGE = "Usage: diagonal workflows [--json]";
249238
249238
  var RUN_USAGE = "Usage: diagonal run <path> [--input '<json object>'] [--json]";
249239
+ var LOGS_USAGE = "Usage: diagonal logs [path | execution id] [--status <success|error|exception|started|pending>] [--limit <1-100>] [--json]";
249239
249240
  var SUCCESS = "execution.success";
249241
+ var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
249242
+ var STATUSES = ["success", "error", "exception", "started", "pending"];
249240
249243
  function credentials(env2, stderr) {
249241
249244
  const url = env2.DIAGONAL_URL?.trim().replace(/\/+$/, "") ?? "";
249242
249245
  const apiKey = env2.DIAGONAL_API_KEY?.trim() ?? "";
@@ -249369,7 +249372,9 @@ function parseRunArguments(args) {
249369
249372
  return parsed;
249370
249373
  }
249371
249374
  if (parsed.positional.length !== 1) {
249372
- return { error: "Give one workflow path, for example workflows/seed-catalog.ts" };
249375
+ return {
249376
+ error: "Give one workflow path, for example workflows/seed-catalog.ts"
249377
+ };
249373
249378
  }
249374
249379
  const json = parsed.booleans.has("--json");
249375
249380
  const path = parsed.positional[0].replace(/^\.\//, "");
@@ -249427,6 +249432,131 @@ ${RUN_USAGE}
249427
249432
  }
249428
249433
  return succeeded ? 0 : 1;
249429
249434
  }
249435
+ function parseLogsArguments(args) {
249436
+ const parsed = parseFlags(args, ["--status", "--limit"], ["--json"]);
249437
+ if (parsed.error !== void 0) {
249438
+ return parsed;
249439
+ }
249440
+ if (parsed.positional.length > 1) {
249441
+ return { error: "Give at most one workflow path or execution id" };
249442
+ }
249443
+ const target = parsed.positional[0]?.replace(/^\.\//, "") ?? null;
249444
+ const status = parsed.values["--status"] ?? null;
249445
+ const rawLimit = parsed.values["--limit"];
249446
+ const limit = rawLimit === void 0 ? null : Number(rawLimit);
249447
+ if (status !== null && !STATUSES.includes(status)) {
249448
+ return { error: `--status must be one of ${STATUSES.join(", ")}` };
249449
+ }
249450
+ if (limit !== null && (!Number.isInteger(limit) || limit < 1 || limit > 100)) {
249451
+ return { error: "--limit must be a whole number from 1 to 100" };
249452
+ }
249453
+ const execution = target !== null && UUID.test(target) ? target : null;
249454
+ if (execution !== null && (status !== null || limit !== null)) {
249455
+ return {
249456
+ error: "--status and --limit apply to a list of runs, not to one execution"
249457
+ };
249458
+ }
249459
+ return {
249460
+ execution,
249461
+ path: execution === null ? target : null,
249462
+ status,
249463
+ limit,
249464
+ json: parsed.booleans.has("--json")
249465
+ };
249466
+ }
249467
+ function runDuration(run) {
249468
+ if (run.duration_ms === null || run.duration_ms === void 0) {
249469
+ return "";
249470
+ }
249471
+ return run.duration_ms < 1e3 ? `${run.duration_ms}ms` : `${(run.duration_ms / 1e3).toFixed(1)}s`;
249472
+ }
249473
+ function errorLines(error, indent) {
249474
+ if (error === null || error === void 0) {
249475
+ return [];
249476
+ }
249477
+ const lines = [`${indent}${error.type ?? "Error"}: ${error.message ?? "(no message)"}`];
249478
+ const fieldErrors = Array.isArray(error.errors) ? error.errors : Object.entries(error.errors ?? {});
249479
+ for (const [field2, messages] of fieldErrors) {
249480
+ for (const message of Array.isArray(messages) ? messages : [messages]) {
249481
+ lines.push(`${indent} ${field2}: ${message}`);
249482
+ }
249483
+ }
249484
+ return lines;
249485
+ }
249486
+ function runLine(run) {
249487
+ const trigger = run.trigger?.request_path ?? run.trigger?.type ?? "";
249488
+ const status = run.response_status_code === null ? run.status : `${run.status} ${run.response_status_code}`;
249489
+ return [run.started_at, status, run.path, trigger, runDuration(run), run.execution_id].filter((part) => part !== "").join(" ");
249490
+ }
249491
+ async function showLogs(args, { env: env2, stdout, stderr }) {
249492
+ const parsed = parseLogsArguments(args);
249493
+ if (parsed.error !== void 0) {
249494
+ stderr.write(`${parsed.error}
249495
+ ${LOGS_USAGE}
249496
+ `);
249497
+ return 2;
249498
+ }
249499
+ const target = credentials(env2, stderr);
249500
+ if (target === null) {
249501
+ return 2;
249502
+ }
249503
+ if (parsed.execution !== null) {
249504
+ const run = await request(
249505
+ target,
249506
+ "GET",
249507
+ `/api/runtime/executions/${parsed.execution}`,
249508
+ void 0,
249509
+ stderr
249510
+ );
249511
+ if (run === null) {
249512
+ return 1;
249513
+ }
249514
+ if (parsed.json) {
249515
+ stdout.write(`${JSON.stringify(run, null, 2)}
249516
+ `);
249517
+ return 0;
249518
+ }
249519
+ stdout.write(`${runLine(run)}
249520
+ `);
249521
+ if (run.error !== null) {
249522
+ stdout.write(`${JSON.stringify(run.error, null, 2)}
249523
+ `);
249524
+ } else if (run.output !== null) {
249525
+ stdout.write(`${JSON.stringify(run.output, null, 2)}
249526
+ `);
249527
+ }
249528
+ return 0;
249529
+ }
249530
+ const query = new URLSearchParams();
249531
+ if (parsed.path !== null) {
249532
+ query.set("workflow", parsed.path);
249533
+ }
249534
+ if (parsed.status !== null) {
249535
+ query.set("status", parsed.status);
249536
+ }
249537
+ if (parsed.limit !== null) {
249538
+ query.set("limit", String(parsed.limit));
249539
+ }
249540
+ const suffix = query.size === 0 ? "" : `?${query}`;
249541
+ const body = await request(target, "GET", `/api/runtime/executions${suffix}`, void 0, stderr);
249542
+ if (body === null) {
249543
+ return 1;
249544
+ }
249545
+ if (parsed.json) {
249546
+ stdout.write(`${JSON.stringify(body, null, 2)}
249547
+ `);
249548
+ return 0;
249549
+ }
249550
+ if (body.data.length === 0) {
249551
+ stdout.write("No runs.\n");
249552
+ return 0;
249553
+ }
249554
+ for (const run of [...body.data].reverse()) {
249555
+ stdout.write(`${[runLine(run), ...errorLines(run.error, " ")].join("\n")}
249556
+ `);
249557
+ }
249558
+ return 0;
249559
+ }
249430
249560
 
249431
249561
  // scripts/lib/runtime-build/assets-cli.mjs
249432
249562
  init_define_globalThis_DIAGONAL_SDK_RUNTIME();
@@ -301507,7 +301637,7 @@ var CONFIG_KEYS = /* @__PURE__ */ new Set(["title", "description", "trigger", "r
301507
301637
  var HTTP_METHODS = ["GET", "POST", "PUT", "PATCH", "DELETE"];
301508
301638
  var RECORD_EVENTS = ["created", "updated", "deleted", "restored", "saved"];
301509
301639
  var LIFECYCLE_HOOKS = ["creating", "updating", "saving", "deleting", "restoring"];
301510
- var WORKFLOW_EVENTS = ["execution.success", "execution.error"];
301640
+ var WORKFLOW_EVENTS = ["execution.success", "execution.error", "execution.exception"];
301511
301641
  var SCHEDULE_FIELD_TYPES = /* @__PURE__ */ new Set(["date", "datetime"]);
301512
301642
  var TRIGGERS = {
301513
301643
  request: {
@@ -302698,6 +302828,7 @@ var USAGE = [
302698
302828
  CHECK_USAGE,
302699
302829
  WORKFLOWS_USAGE,
302700
302830
  RUN_USAGE,
302831
+ LOGS_USAGE,
302701
302832
  ASSETS_UPLOAD_USAGE,
302702
302833
  ASSETS_LIST_USAGE
302703
302834
  ].join("\n");
@@ -302772,6 +302903,8 @@ ${ASSETS_LIST_USAGE}
302772
302903
  return listWorkflows(args, io);
302773
302904
  case "run":
302774
302905
  return runWorkflow(args, io);
302906
+ case "logs":
302907
+ return showLogs(args, io);
302775
302908
  default:
302776
302909
  io.stderr.write(`${USAGE}
302777
302910
  `);
package/dist/index.d.ts CHANGED
@@ -358,7 +358,7 @@ export type WorkflowEventTrigger = {
358
358
  type: 'workflowEvent';
359
359
  /** The path of another workflow, for example `'workflows/welcome.ts'`. */
360
360
  workflow: `workflows/${string}.ts`;
361
- event: 'execution.success' | 'execution.error';
361
+ event: 'execution.success' | 'execution.error' | 'execution.exception';
362
362
  };
363
363
 
364
364
  export type ManualTrigger = { type: 'manual' };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diagonal-hq/cli",
3
- "version": "0.10.0",
3
+ "version": "0.10.2",
4
4
  "description": "The diagonal CLI and the configuration helpers for file-based Diagonal workspaces.",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "repository": {