@openfn/cli 1.20.1 → 1.20.3
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 +2 -1
- package/dist/process/runner.js +124 -128
- package/package.json +7 -7
package/dist/index.js
CHANGED
package/dist/process/runner.js
CHANGED
|
@@ -486,6 +486,9 @@ async function compile_default(planOrPath, opts, log2) {
|
|
|
486
486
|
var compileJob = async (job, opts, log2, jobName) => {
|
|
487
487
|
try {
|
|
488
488
|
const compilerOptions = await loadTransformOptions(opts, log2);
|
|
489
|
+
if (jobName) {
|
|
490
|
+
compilerOptions.name = jobName;
|
|
491
|
+
}
|
|
489
492
|
return compile(job, compilerOptions);
|
|
490
493
|
} catch (e) {
|
|
491
494
|
abort_default(
|
|
@@ -512,7 +515,7 @@ var compileWorkflow = async (plan, opts, log2) => {
|
|
|
512
515
|
job.expression,
|
|
513
516
|
jobOpts,
|
|
514
517
|
log2,
|
|
515
|
-
job.id
|
|
518
|
+
job.name ?? job.id
|
|
516
519
|
);
|
|
517
520
|
job.expression = code;
|
|
518
521
|
job.sourceMap = map;
|
|
@@ -1603,7 +1606,7 @@ var handler_default5 = testHandler;
|
|
|
1603
1606
|
|
|
1604
1607
|
// src/deploy/handler.ts
|
|
1605
1608
|
import {
|
|
1606
|
-
DeployError,
|
|
1609
|
+
DeployError as DeployError2,
|
|
1607
1610
|
deploy,
|
|
1608
1611
|
getConfig,
|
|
1609
1612
|
validateConfig
|
|
@@ -1612,22 +1615,120 @@ import {
|
|
|
1612
1615
|
// src/deploy/beta.ts
|
|
1613
1616
|
import Project2 from "@openfn/project";
|
|
1614
1617
|
import { deployProject } from "@openfn/deploy";
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
+
|
|
1619
|
+
// src/projects/util.ts
|
|
1620
|
+
import path7 from "node:path";
|
|
1621
|
+
import { mkdir as mkdir3, writeFile as writeFile5 } from "node:fs/promises";
|
|
1622
|
+
|
|
1623
|
+
// src/errors.ts
|
|
1624
|
+
var CLIError = class extends Error {
|
|
1625
|
+
constructor(message) {
|
|
1626
|
+
super(message);
|
|
1627
|
+
}
|
|
1628
|
+
};
|
|
1629
|
+
|
|
1630
|
+
// src/projects/util.ts
|
|
1631
|
+
var loadAppAuthConfig = (options6, logger) => {
|
|
1632
|
+
const { OPENFN_API_KEY, OPENFN_ENDPOINT } = process.env;
|
|
1618
1633
|
const config2 = {
|
|
1619
|
-
apiKey: options6.apiKey
|
|
1634
|
+
apiKey: options6.apiKey,
|
|
1635
|
+
endpoint: options6.endpoint
|
|
1620
1636
|
};
|
|
1621
1637
|
if (!options6.apiKey && OPENFN_API_KEY) {
|
|
1622
1638
|
logger.info("Using OPENFN_API_KEY environment variable");
|
|
1623
1639
|
config2.apiKey = OPENFN_API_KEY;
|
|
1624
1640
|
}
|
|
1625
|
-
|
|
1626
|
-
|
|
1641
|
+
if (!options6.endpoint && OPENFN_ENDPOINT) {
|
|
1642
|
+
logger.info("Using OPENFN_ENDPOINT environment variable");
|
|
1643
|
+
config2.endpoint = OPENFN_ENDPOINT;
|
|
1644
|
+
}
|
|
1645
|
+
return config2;
|
|
1646
|
+
};
|
|
1647
|
+
var ensureExt = (filePath, ext) => {
|
|
1648
|
+
if (!filePath.endsWith(ext)) {
|
|
1649
|
+
return `${filePath}.${ext}`;
|
|
1650
|
+
}
|
|
1651
|
+
return filePath;
|
|
1652
|
+
};
|
|
1653
|
+
var serialize = async (project, outputPath2, formatOverride, dryRun = false) => {
|
|
1654
|
+
const root = path7.dirname(outputPath2);
|
|
1655
|
+
await mkdir3(root, { recursive: true });
|
|
1656
|
+
const format = formatOverride ?? project.config?.formats.project;
|
|
1657
|
+
const output = project?.serialize("project", { format });
|
|
1658
|
+
const maybeWriteFile = (filePath, output2) => {
|
|
1659
|
+
if (!dryRun) {
|
|
1660
|
+
return writeFile5(filePath, output2);
|
|
1661
|
+
}
|
|
1662
|
+
};
|
|
1663
|
+
let finalPath;
|
|
1664
|
+
if (format === "yaml") {
|
|
1665
|
+
finalPath = ensureExt(outputPath2, "yaml");
|
|
1666
|
+
await maybeWriteFile(finalPath, output);
|
|
1667
|
+
} else {
|
|
1668
|
+
finalPath = ensureExt(outputPath2, "json");
|
|
1669
|
+
await maybeWriteFile(finalPath, JSON.stringify(output, null, 2));
|
|
1670
|
+
}
|
|
1671
|
+
return finalPath;
|
|
1672
|
+
};
|
|
1673
|
+
var getLightningUrl = (config2, path15 = "", snapshots2) => {
|
|
1674
|
+
const params = new URLSearchParams();
|
|
1675
|
+
snapshots2?.forEach((snapshot) => params.append("snapshots[]", snapshot));
|
|
1676
|
+
return new URL(
|
|
1677
|
+
`/api/provision/${path15}?${params.toString()}`,
|
|
1678
|
+
config2.endpoint
|
|
1679
|
+
);
|
|
1680
|
+
};
|
|
1681
|
+
async function getProject(logger, config2, projectId2, snapshots2) {
|
|
1682
|
+
const url2 = getLightningUrl(config2, projectId2, snapshots2);
|
|
1683
|
+
logger.info(`Checking ${url2} for existing project`);
|
|
1684
|
+
try {
|
|
1685
|
+
const response = await fetch(url2, {
|
|
1686
|
+
headers: {
|
|
1687
|
+
Authorization: `Bearer ${config2.apiKey}`,
|
|
1688
|
+
Accept: "application/json"
|
|
1689
|
+
}
|
|
1690
|
+
});
|
|
1691
|
+
if (!response.ok) {
|
|
1692
|
+
if (response.status === 401 || response.status === 403) {
|
|
1693
|
+
throw new CLIError(
|
|
1694
|
+
`Failed to authorize request with endpoint ${config2.endpoint}, got ${response.status} ${response.statusText}`
|
|
1695
|
+
);
|
|
1696
|
+
}
|
|
1697
|
+
if (response.status === 404) {
|
|
1698
|
+
throw new CLIError(`Project not found: ${projectId2}`);
|
|
1699
|
+
}
|
|
1700
|
+
throw new CLIError(
|
|
1701
|
+
`Failed to fetch project ${projectId2}: ${response.statusText}`
|
|
1702
|
+
);
|
|
1703
|
+
}
|
|
1704
|
+
logger.info("Project found");
|
|
1705
|
+
return response.json();
|
|
1706
|
+
} catch (error) {
|
|
1707
|
+
handleCommonErrors(config2, error);
|
|
1708
|
+
throw error;
|
|
1709
|
+
}
|
|
1710
|
+
}
|
|
1711
|
+
function handleCommonErrors(config2, error) {
|
|
1712
|
+
if (error.cause?.code === "ECONNREFUSED") {
|
|
1713
|
+
throw new DeployError(
|
|
1714
|
+
`Failed to connect to endpoint ${config2.endpoint}, got ECONNREFUSED.`
|
|
1715
|
+
);
|
|
1716
|
+
}
|
|
1717
|
+
}
|
|
1718
|
+
var DeployError = class extends Error {
|
|
1719
|
+
constructor(message) {
|
|
1720
|
+
super(message);
|
|
1721
|
+
}
|
|
1722
|
+
};
|
|
1723
|
+
|
|
1724
|
+
// src/deploy/beta.ts
|
|
1725
|
+
async function handler(options6, logger) {
|
|
1726
|
+
const config2 = loadAppAuthConfig(options6, logger);
|
|
1727
|
+
const project = await Project2.from("fs", { root: options6.workspace || "." });
|
|
1627
1728
|
const state = project.serialize("state", { format: "json" });
|
|
1628
1729
|
logger.debug("Converted local project to app state:");
|
|
1629
1730
|
logger.debug(JSON.stringify(state, null, 2));
|
|
1630
|
-
config2.endpoint
|
|
1731
|
+
config2.endpoint ??= project.openfn?.endpoint;
|
|
1631
1732
|
logger.info("Sending project to app...");
|
|
1632
1733
|
await deployProject(config2, state);
|
|
1633
1734
|
logger.success("Updated project at", config2.endpoint);
|
|
@@ -1660,7 +1761,7 @@ async function deployHandler(options6, logger, deployFn = actualDeploy) {
|
|
|
1660
1761
|
process.exitCode = isOk ? 0 : 1;
|
|
1661
1762
|
return isOk;
|
|
1662
1763
|
} catch (error) {
|
|
1663
|
-
if (error instanceof
|
|
1764
|
+
if (error instanceof DeployError2) {
|
|
1664
1765
|
logger.error(error.message);
|
|
1665
1766
|
process.exitCode = 10;
|
|
1666
1767
|
return false;
|
|
@@ -1685,26 +1786,26 @@ function pickFirst(...args) {
|
|
|
1685
1786
|
var handler_default6 = deployHandler;
|
|
1686
1787
|
|
|
1687
1788
|
// src/docgen/handler.ts
|
|
1688
|
-
import { writeFile as
|
|
1789
|
+
import { writeFile as writeFile6 } from "node:fs/promises";
|
|
1689
1790
|
import { readFileSync, writeFileSync, mkdirSync, rmSync } from "node:fs";
|
|
1690
|
-
import
|
|
1791
|
+
import path8 from "node:path";
|
|
1691
1792
|
import { describePackage } from "@openfn/describe-package";
|
|
1692
1793
|
import { getNameAndVersion as getNameAndVersion4 } from "@openfn/runtime";
|
|
1693
1794
|
var RETRY_DURATION = 500;
|
|
1694
1795
|
var RETRY_COUNT = 20;
|
|
1695
1796
|
var TIMEOUT_MS = 1e3 * 60;
|
|
1696
1797
|
var actualDocGen = (specifier) => describePackage(specifier, {});
|
|
1697
|
-
var ensurePath = (filePath) => mkdirSync(
|
|
1798
|
+
var ensurePath = (filePath) => mkdirSync(path8.dirname(filePath), { recursive: true });
|
|
1698
1799
|
var generatePlaceholder = (path15) => {
|
|
1699
1800
|
writeFileSync(path15, `{ "loading": true, "timestamp": ${Date.now()}}`);
|
|
1700
1801
|
};
|
|
1701
1802
|
var finish = (logger, resultPath) => {
|
|
1702
1803
|
logger.success("Done! Docs can be found at:\n");
|
|
1703
|
-
logger.print(` ${
|
|
1804
|
+
logger.print(` ${path8.resolve(resultPath)}`);
|
|
1704
1805
|
};
|
|
1705
1806
|
var generateDocs = async (specifier, path15, docgen, logger) => {
|
|
1706
1807
|
const result = await docgen(specifier);
|
|
1707
|
-
await
|
|
1808
|
+
await writeFile6(path15, JSON.stringify(result, null, 2));
|
|
1708
1809
|
finish(logger, path15);
|
|
1709
1810
|
return path15;
|
|
1710
1811
|
};
|
|
@@ -1869,13 +1970,13 @@ var handler_default8 = docsHandler;
|
|
|
1869
1970
|
// src/metadata/cache.ts
|
|
1870
1971
|
import { getNameAndVersion as getNameAndVersion6 } from "@openfn/runtime";
|
|
1871
1972
|
import { createHash } from "node:crypto";
|
|
1872
|
-
import { mkdir as
|
|
1873
|
-
import
|
|
1973
|
+
import { mkdir as mkdir4, readFile as readFile5, writeFile as writeFile7, readdir, rm } from "node:fs/promises";
|
|
1974
|
+
import path9 from "node:path";
|
|
1874
1975
|
var UNSUPPORTED_FILE_NAME = "unsupported.json";
|
|
1875
1976
|
var getCachePath2 = (repoDir, key) => {
|
|
1876
|
-
const base =
|
|
1977
|
+
const base = path9.join(repoDir, "meta");
|
|
1877
1978
|
if (key) {
|
|
1878
|
-
return
|
|
1979
|
+
return path9.join(base, key.endsWith(".json") ? key : `${key}.json`);
|
|
1879
1980
|
}
|
|
1880
1981
|
return base;
|
|
1881
1982
|
};
|
|
@@ -1917,8 +2018,8 @@ var get2 = async (repoPath, key) => {
|
|
|
1917
2018
|
};
|
|
1918
2019
|
var set2 = async (repoPath, key, result) => {
|
|
1919
2020
|
const p = getCachePath2(repoPath, key);
|
|
1920
|
-
await
|
|
1921
|
-
await
|
|
2021
|
+
await mkdir4(path9.dirname(p), { recursive: true });
|
|
2022
|
+
await writeFile7(p, JSON.stringify(result));
|
|
1922
2023
|
};
|
|
1923
2024
|
var getUnsupportedCachePath = (repoDir) => {
|
|
1924
2025
|
return getCachePath2(repoDir, UNSUPPORTED_FILE_NAME);
|
|
@@ -1976,8 +2077,8 @@ var markAdaptorAsUnsupported = async (adaptorSpecifier, repoDir) => {
|
|
|
1976
2077
|
majorMinor: parsed.majorMinor,
|
|
1977
2078
|
timestamp: Date.now()
|
|
1978
2079
|
};
|
|
1979
|
-
await
|
|
1980
|
-
await
|
|
2080
|
+
await mkdir4(path9.dirname(cachePath), { recursive: true });
|
|
2081
|
+
await writeFile7(cachePath, JSON.stringify(cache, null, 2));
|
|
1981
2082
|
}
|
|
1982
2083
|
};
|
|
1983
2084
|
|
|
@@ -2402,111 +2503,6 @@ var workspace = {
|
|
|
2402
2503
|
}
|
|
2403
2504
|
};
|
|
2404
2505
|
|
|
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
2506
|
// src/projects/fetch.ts
|
|
2511
2507
|
var options = [
|
|
2512
2508
|
apikey,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openfn/cli",
|
|
3
|
-
"version": "1.20.
|
|
3
|
+
"version": "1.20.3",
|
|
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.
|
|
53
|
-
"@openfn/deploy": "0.11.4",
|
|
52
|
+
"@openfn/compiler": "1.2.2",
|
|
54
53
|
"@openfn/describe-package": "0.1.5",
|
|
55
|
-
"@openfn/
|
|
56
|
-
"@openfn/
|
|
57
|
-
"@openfn/
|
|
58
|
-
"@openfn/
|
|
54
|
+
"@openfn/deploy": "0.11.5",
|
|
55
|
+
"@openfn/lexicon": "^1.3.0",
|
|
56
|
+
"@openfn/project": "^0.9.3",
|
|
57
|
+
"@openfn/runtime": "1.7.7",
|
|
58
|
+
"@openfn/logger": "1.1.1"
|
|
59
59
|
},
|
|
60
60
|
"files": [
|
|
61
61
|
"dist",
|