@openfn/cli 1.20.1 → 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
@@ -917,7 +917,8 @@ var options3 = [
917
917
  log,
918
918
  logJson,
919
919
  projectPath,
920
- statePath
920
+ statePath,
921
+ override(workspace, { hidden: true })
921
922
  ];
922
923
  var deployCommand = {
923
924
  command: "deploy",
@@ -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
 
@@ -2402,111 +2500,6 @@ var workspace = {
2402
2500
  }
2403
2501
  };
2404
2502
 
2405
- // src/projects/util.ts
2406
- import path9 from "node:path";
2407
- import { mkdir as mkdir4, writeFile as writeFile7 } from "node:fs/promises";
2408
-
2409
- // src/errors.ts
2410
- var CLIError = class extends Error {
2411
- constructor(message) {
2412
- super(message);
2413
- }
2414
- };
2415
-
2416
- // src/projects/util.ts
2417
- var loadAppAuthConfig = (options6, logger) => {
2418
- const { OPENFN_API_KEY, OPENFN_ENDPOINT } = process.env;
2419
- const config2 = {
2420
- apiKey: options6.apiKey,
2421
- endpoint: options6.endpoint
2422
- };
2423
- if (!options6.apiKey && OPENFN_API_KEY) {
2424
- logger.info("Using OPENFN_API_KEY environment variable");
2425
- config2.apiKey = OPENFN_API_KEY;
2426
- }
2427
- if (!options6.endpoint && OPENFN_ENDPOINT) {
2428
- logger.info("Using OPENFN_ENDPOINT environment variable");
2429
- config2.endpoint = OPENFN_ENDPOINT;
2430
- }
2431
- return config2;
2432
- };
2433
- var ensureExt = (filePath, ext) => {
2434
- if (!filePath.endsWith(ext)) {
2435
- return `${filePath}.${ext}`;
2436
- }
2437
- return filePath;
2438
- };
2439
- var serialize = async (project, outputPath2, formatOverride, dryRun = false) => {
2440
- const root = path9.dirname(outputPath2);
2441
- await mkdir4(root, { recursive: true });
2442
- const format = formatOverride ?? project.config?.formats.project;
2443
- const output = project?.serialize("project", { format });
2444
- const maybeWriteFile = (filePath, output2) => {
2445
- if (!dryRun) {
2446
- return writeFile7(filePath, output2);
2447
- }
2448
- };
2449
- let finalPath;
2450
- if (format === "yaml") {
2451
- finalPath = ensureExt(outputPath2, "yaml");
2452
- await maybeWriteFile(finalPath, output);
2453
- } else {
2454
- finalPath = ensureExt(outputPath2, "json");
2455
- await maybeWriteFile(finalPath, JSON.stringify(output, null, 2));
2456
- }
2457
- return finalPath;
2458
- };
2459
- var getLightningUrl = (config2, path15 = "", snapshots2) => {
2460
- const params = new URLSearchParams();
2461
- snapshots2?.forEach((snapshot) => params.append("snapshots[]", snapshot));
2462
- return new URL(
2463
- `/api/provision/${path15}?${params.toString()}`,
2464
- config2.endpoint
2465
- );
2466
- };
2467
- async function getProject(logger, config2, projectId2, snapshots2) {
2468
- const url2 = getLightningUrl(config2, projectId2, snapshots2);
2469
- logger.info(`Checking ${url2} for existing project`);
2470
- try {
2471
- const response = await fetch(url2, {
2472
- headers: {
2473
- Authorization: `Bearer ${config2.apiKey}`,
2474
- Accept: "application/json"
2475
- }
2476
- });
2477
- if (!response.ok) {
2478
- if (response.status === 401 || response.status === 403) {
2479
- throw new CLIError(
2480
- `Failed to authorize request with endpoint ${config2.endpoint}, got ${response.status} ${response.statusText}`
2481
- );
2482
- }
2483
- if (response.status === 404) {
2484
- throw new CLIError(`Project not found: ${projectId2}`);
2485
- }
2486
- throw new CLIError(
2487
- `Failed to fetch project ${projectId2}: ${response.statusText}`
2488
- );
2489
- }
2490
- logger.info("Project found");
2491
- return response.json();
2492
- } catch (error) {
2493
- handleCommonErrors(config2, error);
2494
- throw error;
2495
- }
2496
- }
2497
- function handleCommonErrors(config2, error) {
2498
- if (error.cause?.code === "ECONNREFUSED") {
2499
- throw new DeployError2(
2500
- `Failed to connect to endpoint ${config2.endpoint}, got ECONNREFUSED.`
2501
- );
2502
- }
2503
- }
2504
- var DeployError2 = class extends Error {
2505
- constructor(message) {
2506
- super(message);
2507
- }
2508
- };
2509
-
2510
2503
  // src/projects/fetch.ts
2511
2504
  var options = [
2512
2505
  apikey,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openfn/cli",
3
- "version": "1.20.1",
3
+ "version": "1.20.2",
4
4
  "description": "CLI devtools for the OpenFn toolchain",
5
5
  "engines": {
6
6
  "node": ">=18",
@@ -51,11 +51,11 @@
51
51
  "yargs": "^17.7.2",
52
52
  "@openfn/compiler": "1.2.1",
53
53
  "@openfn/deploy": "0.11.4",
54
- "@openfn/describe-package": "0.1.5",
55
- "@openfn/lexicon": "^1.2.7",
56
54
  "@openfn/logger": "1.1.0",
55
+ "@openfn/describe-package": "0.1.5",
56
+ "@openfn/project": "^0.9.2",
57
57
  "@openfn/runtime": "1.7.6",
58
- "@openfn/project": "^0.9.1"
58
+ "@openfn/lexicon": "^1.3.0"
59
59
  },
60
60
  "files": [
61
61
  "dist",