@openfn/cli 1.20.0 → 1.20.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/dist/index.js CHANGED
@@ -629,6 +629,7 @@ var ensure = (command6, opts2) => (yargs2) => {
629
629
  try {
630
630
  opt.ensure(yargs2);
631
631
  } catch (e) {
632
+ console.log(e);
632
633
  console.error(
633
634
  c.red(`
634
635
  Error parsing command arguments: ${command6}.${opt.name}
@@ -725,9 +726,10 @@ var token = {
725
726
  description: "Lightning Personal Access Token (PAT)"
726
727
  }
727
728
  };
728
- var lightningUrl = {
729
- name: "lightning",
729
+ var endpoint2 = {
730
+ name: "endpoint",
730
731
  yargs: {
732
+ alias: ["e", "lightning"],
731
733
  description: "URL to OpenFn server. Defaults to OPENFN_ENDPOINT or https://app.openfn.org"
732
734
  }
733
735
  };
@@ -780,7 +782,7 @@ var getOptions = [
780
782
  collectionName,
781
783
  key,
782
784
  token,
783
- lightningUrl,
785
+ endpoint2,
784
786
  pageSize,
785
787
  limit,
786
788
  pretty,
@@ -816,7 +818,7 @@ var removeOptions = [
816
818
  collectionName,
817
819
  key,
818
820
  token,
819
- lightningUrl,
821
+ endpoint2,
820
822
  dryRun,
821
823
  createdBefore,
822
824
  createdAfter,
@@ -851,7 +853,7 @@ var setOptions = [
851
853
  demand: false
852
854
  }),
853
855
  token,
854
- lightningUrl,
856
+ endpoint2,
855
857
  value,
856
858
  items,
857
859
  override(log, {
@@ -915,7 +917,8 @@ var options3 = [
915
917
  log,
916
918
  logJson,
917
919
  projectPath,
918
- statePath
920
+ statePath,
921
+ override(workspace, { hidden: true })
919
922
  ];
920
923
  var deployCommand = {
921
924
  command: "deploy",
@@ -1344,7 +1344,7 @@ var request_default = async (method, options6, logger) => {
1344
1344
  logger.error(e);
1345
1345
  throwAbortableError(
1346
1346
  `CONNECTION_REFUSED: error connecting to server at ${base}`,
1347
- "Check you have passed the correct URL to --lightning or OPENFN_ENDPOINT"
1347
+ "Check you have passed the correct URL to --endpoint or OPENFN_ENDPOINT"
1348
1348
  );
1349
1349
  }
1350
1350
  } while (cursor && count < limit);
@@ -1432,7 +1432,7 @@ var get = async (options6, logger) => {
1432
1432
  let result = await request_default(
1433
1433
  "GET",
1434
1434
  {
1435
- lightning: options6.lightning,
1435
+ lightning: options6.endpoint,
1436
1436
  token: options6.token,
1437
1437
  pageSize: options6.pageSize,
1438
1438
  limit: options6.limit,
@@ -1492,7 +1492,7 @@ var set = async (options6, logger) => {
1492
1492
  const result = await request_default(
1493
1493
  "POST",
1494
1494
  {
1495
- lightning: options6.lightning,
1495
+ lightning: options6.endpoint,
1496
1496
  token: options6.token,
1497
1497
  key: options6.key,
1498
1498
  collectionName: options6.collectionName,
@@ -1512,7 +1512,7 @@ var remove = async (options6, logger) => {
1512
1512
  let result = await request_default(
1513
1513
  "GET",
1514
1514
  {
1515
- lightning: options6.lightning,
1515
+ lightning: options6.endpoint,
1516
1516
  token: options6.token,
1517
1517
  key: options6.key,
1518
1518
  collectionName: options6.collectionName
@@ -1527,7 +1527,7 @@ var remove = async (options6, logger) => {
1527
1527
  let result = await request_default(
1528
1528
  "DELETE",
1529
1529
  {
1530
- lightning: options6.lightning,
1530
+ lightning: options6.endpoint,
1531
1531
  token: options6.token,
1532
1532
  key: options6.key,
1533
1533
  collectionName: options6.collectionName,
@@ -1603,7 +1603,7 @@ var handler_default5 = testHandler;
1603
1603
 
1604
1604
  // src/deploy/handler.ts
1605
1605
  import {
1606
- DeployError,
1606
+ DeployError as DeployError2,
1607
1607
  deploy,
1608
1608
  getConfig,
1609
1609
  validateConfig
@@ -1612,22 +1612,120 @@ import {
1612
1612
  // src/deploy/beta.ts
1613
1613
  import Project2 from "@openfn/project";
1614
1614
  import { deployProject } from "@openfn/deploy";
1615
- async function handler(options6, logger) {
1616
- const { OPENFN_API_KEY } = process.env;
1617
- const { endpoint: endpoint2 } = options6;
1615
+
1616
+ // src/projects/util.ts
1617
+ import path7 from "node:path";
1618
+ import { mkdir as mkdir3, writeFile as writeFile5 } from "node:fs/promises";
1619
+
1620
+ // src/errors.ts
1621
+ var CLIError = class extends Error {
1622
+ constructor(message) {
1623
+ super(message);
1624
+ }
1625
+ };
1626
+
1627
+ // src/projects/util.ts
1628
+ var loadAppAuthConfig = (options6, logger) => {
1629
+ const { OPENFN_API_KEY, OPENFN_ENDPOINT } = process.env;
1618
1630
  const config2 = {
1619
- apiKey: options6.apiKey
1631
+ apiKey: options6.apiKey,
1632
+ endpoint: options6.endpoint
1620
1633
  };
1621
1634
  if (!options6.apiKey && OPENFN_API_KEY) {
1622
1635
  logger.info("Using OPENFN_API_KEY environment variable");
1623
1636
  config2.apiKey = OPENFN_API_KEY;
1624
1637
  }
1625
- const project = await Project2.from("fs", { root: options6.path || "." });
1626
- console.log({ openfn: project.openfn });
1638
+ if (!options6.endpoint && OPENFN_ENDPOINT) {
1639
+ logger.info("Using OPENFN_ENDPOINT environment variable");
1640
+ config2.endpoint = OPENFN_ENDPOINT;
1641
+ }
1642
+ return config2;
1643
+ };
1644
+ var ensureExt = (filePath, ext) => {
1645
+ if (!filePath.endsWith(ext)) {
1646
+ return `${filePath}.${ext}`;
1647
+ }
1648
+ return filePath;
1649
+ };
1650
+ var serialize = async (project, outputPath2, formatOverride, dryRun = false) => {
1651
+ const root = path7.dirname(outputPath2);
1652
+ await mkdir3(root, { recursive: true });
1653
+ const format = formatOverride ?? project.config?.formats.project;
1654
+ const output = project?.serialize("project", { format });
1655
+ const maybeWriteFile = (filePath, output2) => {
1656
+ if (!dryRun) {
1657
+ return writeFile5(filePath, output2);
1658
+ }
1659
+ };
1660
+ let finalPath;
1661
+ if (format === "yaml") {
1662
+ finalPath = ensureExt(outputPath2, "yaml");
1663
+ await maybeWriteFile(finalPath, output);
1664
+ } else {
1665
+ finalPath = ensureExt(outputPath2, "json");
1666
+ await maybeWriteFile(finalPath, JSON.stringify(output, null, 2));
1667
+ }
1668
+ return finalPath;
1669
+ };
1670
+ var getLightningUrl = (config2, path15 = "", snapshots2) => {
1671
+ const params = new URLSearchParams();
1672
+ snapshots2?.forEach((snapshot) => params.append("snapshots[]", snapshot));
1673
+ return new URL(
1674
+ `/api/provision/${path15}?${params.toString()}`,
1675
+ config2.endpoint
1676
+ );
1677
+ };
1678
+ async function getProject(logger, config2, projectId2, snapshots2) {
1679
+ const url2 = getLightningUrl(config2, projectId2, snapshots2);
1680
+ logger.info(`Checking ${url2} for existing project`);
1681
+ try {
1682
+ const response = await fetch(url2, {
1683
+ headers: {
1684
+ Authorization: `Bearer ${config2.apiKey}`,
1685
+ Accept: "application/json"
1686
+ }
1687
+ });
1688
+ if (!response.ok) {
1689
+ if (response.status === 401 || response.status === 403) {
1690
+ throw new CLIError(
1691
+ `Failed to authorize request with endpoint ${config2.endpoint}, got ${response.status} ${response.statusText}`
1692
+ );
1693
+ }
1694
+ if (response.status === 404) {
1695
+ throw new CLIError(`Project not found: ${projectId2}`);
1696
+ }
1697
+ throw new CLIError(
1698
+ `Failed to fetch project ${projectId2}: ${response.statusText}`
1699
+ );
1700
+ }
1701
+ logger.info("Project found");
1702
+ return response.json();
1703
+ } catch (error) {
1704
+ handleCommonErrors(config2, error);
1705
+ throw error;
1706
+ }
1707
+ }
1708
+ function handleCommonErrors(config2, error) {
1709
+ if (error.cause?.code === "ECONNREFUSED") {
1710
+ throw new DeployError(
1711
+ `Failed to connect to endpoint ${config2.endpoint}, got ECONNREFUSED.`
1712
+ );
1713
+ }
1714
+ }
1715
+ var DeployError = class extends Error {
1716
+ constructor(message) {
1717
+ super(message);
1718
+ }
1719
+ };
1720
+
1721
+ // src/deploy/beta.ts
1722
+ async function handler(options6, logger) {
1723
+ const config2 = loadAppAuthConfig(options6, logger);
1724
+ const project = await Project2.from("fs", { root: options6.workspace || "." });
1627
1725
  const state = project.serialize("state", { format: "json" });
1628
1726
  logger.debug("Converted local project to app state:");
1629
1727
  logger.debug(JSON.stringify(state, null, 2));
1630
- config2.endpoint = endpoint2 || project.openfn?.endpoint;
1728
+ config2.endpoint ??= project.openfn?.endpoint;
1631
1729
  logger.info("Sending project to app...");
1632
1730
  await deployProject(config2, state);
1633
1731
  logger.success("Updated project at", config2.endpoint);
@@ -1660,7 +1758,7 @@ async function deployHandler(options6, logger, deployFn = actualDeploy) {
1660
1758
  process.exitCode = isOk ? 0 : 1;
1661
1759
  return isOk;
1662
1760
  } catch (error) {
1663
- if (error instanceof DeployError) {
1761
+ if (error instanceof DeployError2) {
1664
1762
  logger.error(error.message);
1665
1763
  process.exitCode = 10;
1666
1764
  return false;
@@ -1685,26 +1783,26 @@ function pickFirst(...args) {
1685
1783
  var handler_default6 = deployHandler;
1686
1784
 
1687
1785
  // src/docgen/handler.ts
1688
- import { writeFile as writeFile5 } from "node:fs/promises";
1786
+ import { writeFile as writeFile6 } from "node:fs/promises";
1689
1787
  import { readFileSync, writeFileSync, mkdirSync, rmSync } from "node:fs";
1690
- import path7 from "node:path";
1788
+ import path8 from "node:path";
1691
1789
  import { describePackage } from "@openfn/describe-package";
1692
1790
  import { getNameAndVersion as getNameAndVersion4 } from "@openfn/runtime";
1693
1791
  var RETRY_DURATION = 500;
1694
1792
  var RETRY_COUNT = 20;
1695
1793
  var TIMEOUT_MS = 1e3 * 60;
1696
1794
  var actualDocGen = (specifier) => describePackage(specifier, {});
1697
- var ensurePath = (filePath) => mkdirSync(path7.dirname(filePath), { recursive: true });
1795
+ var ensurePath = (filePath) => mkdirSync(path8.dirname(filePath), { recursive: true });
1698
1796
  var generatePlaceholder = (path15) => {
1699
1797
  writeFileSync(path15, `{ "loading": true, "timestamp": ${Date.now()}}`);
1700
1798
  };
1701
1799
  var finish = (logger, resultPath) => {
1702
1800
  logger.success("Done! Docs can be found at:\n");
1703
- logger.print(` ${path7.resolve(resultPath)}`);
1801
+ logger.print(` ${path8.resolve(resultPath)}`);
1704
1802
  };
1705
1803
  var generateDocs = async (specifier, path15, docgen, logger) => {
1706
1804
  const result = await docgen(specifier);
1707
- await writeFile5(path15, JSON.stringify(result, null, 2));
1805
+ await writeFile6(path15, JSON.stringify(result, null, 2));
1708
1806
  finish(logger, path15);
1709
1807
  return path15;
1710
1808
  };
@@ -1869,13 +1967,13 @@ var handler_default8 = docsHandler;
1869
1967
  // src/metadata/cache.ts
1870
1968
  import { getNameAndVersion as getNameAndVersion6 } from "@openfn/runtime";
1871
1969
  import { createHash } from "node:crypto";
1872
- import { mkdir as mkdir3, readFile as readFile5, writeFile as writeFile6, readdir, rm } from "node:fs/promises";
1873
- import path8 from "node:path";
1970
+ import { mkdir as mkdir4, readFile as readFile5, writeFile as writeFile7, readdir, rm } from "node:fs/promises";
1971
+ import path9 from "node:path";
1874
1972
  var UNSUPPORTED_FILE_NAME = "unsupported.json";
1875
1973
  var getCachePath2 = (repoDir, key) => {
1876
- const base = path8.join(repoDir, "meta");
1974
+ const base = path9.join(repoDir, "meta");
1877
1975
  if (key) {
1878
- return path8.join(base, key.endsWith(".json") ? key : `${key}.json`);
1976
+ return path9.join(base, key.endsWith(".json") ? key : `${key}.json`);
1879
1977
  }
1880
1978
  return base;
1881
1979
  };
@@ -1917,8 +2015,8 @@ var get2 = async (repoPath, key) => {
1917
2015
  };
1918
2016
  var set2 = async (repoPath, key, result) => {
1919
2017
  const p = getCachePath2(repoPath, key);
1920
- await mkdir3(path8.dirname(p), { recursive: true });
1921
- await writeFile6(p, JSON.stringify(result));
2018
+ await mkdir4(path9.dirname(p), { recursive: true });
2019
+ await writeFile7(p, JSON.stringify(result));
1922
2020
  };
1923
2021
  var getUnsupportedCachePath = (repoDir) => {
1924
2022
  return getCachePath2(repoDir, UNSUPPORTED_FILE_NAME);
@@ -1976,8 +2074,8 @@ var markAdaptorAsUnsupported = async (adaptorSpecifier, repoDir) => {
1976
2074
  majorMinor: parsed.majorMinor,
1977
2075
  timestamp: Date.now()
1978
2076
  };
1979
- await mkdir3(path8.dirname(cachePath), { recursive: true });
1980
- await writeFile6(cachePath, JSON.stringify(cache, null, 2));
2077
+ await mkdir4(path9.dirname(cachePath), { recursive: true });
2078
+ await writeFile7(cachePath, JSON.stringify(cache, null, 2));
1981
2079
  }
1982
2080
  };
1983
2081
 
@@ -2132,6 +2230,7 @@ var ensure = (command6, opts) => (yargs) => {
2132
2230
  try {
2133
2231
  opt.ensure(yargs);
2134
2232
  } catch (e) {
2233
+ console.log(e);
2135
2234
  console.error(
2136
2235
  c2.red(`
2137
2236
  Error parsing command arguments: ${command6}.${opt.name}
@@ -2401,111 +2500,6 @@ var workspace = {
2401
2500
  }
2402
2501
  };
2403
2502
 
2404
- // src/projects/util.ts
2405
- import path9 from "node:path";
2406
- import { mkdir as mkdir4, writeFile as writeFile7 } from "node:fs/promises";
2407
-
2408
- // src/errors.ts
2409
- var CLIError = class extends Error {
2410
- constructor(message) {
2411
- super(message);
2412
- }
2413
- };
2414
-
2415
- // src/projects/util.ts
2416
- var loadAppAuthConfig = (options6, logger) => {
2417
- const { OPENFN_API_KEY, OPENFN_ENDPOINT } = process.env;
2418
- const config2 = {
2419
- apiKey: options6.apiKey,
2420
- endpoint: options6.endpoint
2421
- };
2422
- if (!options6.apiKey && OPENFN_API_KEY) {
2423
- logger.info("Using OPENFN_API_KEY environment variable");
2424
- config2.apiKey = OPENFN_API_KEY;
2425
- }
2426
- if (!options6.endpoint && OPENFN_ENDPOINT) {
2427
- logger.info("Using OPENFN_ENDPOINT environment variable");
2428
- config2.endpoint = OPENFN_ENDPOINT;
2429
- }
2430
- return config2;
2431
- };
2432
- var ensureExt = (filePath, ext) => {
2433
- if (!filePath.endsWith(ext)) {
2434
- return `${filePath}.${ext}`;
2435
- }
2436
- return filePath;
2437
- };
2438
- var serialize = async (project, outputPath2, formatOverride, dryRun = false) => {
2439
- const root = path9.dirname(outputPath2);
2440
- await mkdir4(root, { recursive: true });
2441
- const format = formatOverride ?? project.config?.formats.project;
2442
- const output = project?.serialize("project", { format });
2443
- const maybeWriteFile = (filePath, output2) => {
2444
- if (!dryRun) {
2445
- return writeFile7(filePath, output2);
2446
- }
2447
- };
2448
- let finalPath;
2449
- if (format === "yaml") {
2450
- finalPath = ensureExt(outputPath2, "yaml");
2451
- await maybeWriteFile(finalPath, output);
2452
- } else {
2453
- finalPath = ensureExt(outputPath2, "json");
2454
- await maybeWriteFile(finalPath, JSON.stringify(output, null, 2));
2455
- }
2456
- return finalPath;
2457
- };
2458
- var getLightningUrl = (config2, path15 = "", snapshots2) => {
2459
- const params = new URLSearchParams();
2460
- snapshots2?.forEach((snapshot) => params.append("snapshots[]", snapshot));
2461
- return new URL(
2462
- `/api/provision/${path15}?${params.toString()}`,
2463
- config2.endpoint
2464
- );
2465
- };
2466
- async function getProject(logger, config2, projectId2, snapshots2) {
2467
- const url2 = getLightningUrl(config2, projectId2, snapshots2);
2468
- logger.info(`Checking ${url2} for existing project`);
2469
- try {
2470
- const response = await fetch(url2, {
2471
- headers: {
2472
- Authorization: `Bearer ${config2.apiKey}`,
2473
- Accept: "application/json"
2474
- }
2475
- });
2476
- if (!response.ok) {
2477
- if (response.status === 401 || response.status === 403) {
2478
- throw new CLIError(
2479
- `Failed to authorize request with endpoint ${config2.endpoint}, got ${response.status} ${response.statusText}`
2480
- );
2481
- }
2482
- if (response.status === 404) {
2483
- throw new CLIError(`Project not found: ${projectId2}`);
2484
- }
2485
- throw new CLIError(
2486
- `Failed to fetch project ${projectId2}: ${response.statusText}`
2487
- );
2488
- }
2489
- logger.info("Project found");
2490
- return response.json();
2491
- } catch (error) {
2492
- handleCommonErrors(config2, error);
2493
- throw error;
2494
- }
2495
- }
2496
- function handleCommonErrors(config2, error) {
2497
- if (error.cause?.code === "ECONNREFUSED") {
2498
- throw new DeployError2(
2499
- `Failed to connect to endpoint ${config2.endpoint}, got ECONNREFUSED.`
2500
- );
2501
- }
2502
- }
2503
- var DeployError2 = class extends Error {
2504
- constructor(message) {
2505
- super(message);
2506
- }
2507
- };
2508
-
2509
2503
  // src/projects/fetch.ts
2510
2504
  var options = [
2511
2505
  apikey,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openfn/cli",
3
- "version": "1.20.0",
3
+ "version": "1.20.2",
4
4
  "description": "CLI devtools for the OpenFn toolchain",
5
5
  "engines": {
6
6
  "node": ">=18",
@@ -49,13 +49,13 @@
49
49
  "undici": "7.12.0",
50
50
  "ws": "^8.18.3",
51
51
  "yargs": "^17.7.2",
52
+ "@openfn/compiler": "1.2.1",
52
53
  "@openfn/deploy": "0.11.4",
53
- "@openfn/describe-package": "0.1.5",
54
- "@openfn/lexicon": "^1.2.7",
55
54
  "@openfn/logger": "1.1.0",
56
- "@openfn/project": "^0.9.1",
55
+ "@openfn/describe-package": "0.1.5",
56
+ "@openfn/project": "^0.9.2",
57
57
  "@openfn/runtime": "1.7.6",
58
- "@openfn/compiler": "1.2.1"
58
+ "@openfn/lexicon": "^1.3.0"
59
59
  },
60
60
  "files": [
61
61
  "dist",