@openfn/cli 0.4.0 → 0.4.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
@@ -180,7 +180,7 @@ Example config file:
180
180
 
181
181
  // Optional: defaults to OpenFn.org's API, can be overridden or set with
182
182
  // `OPENFN_ENDPOINT` env var
183
- "endpoint": "https://app.openfn.org/api/provision"
183
+ "endpoint": "https://app.openfn.org"
184
184
  }
185
185
  ```
186
186
 
@@ -261,30 +261,28 @@ To see an example workflow, run the test command with `openfn test`.
261
261
 
262
262
  A workflow has a structure like this (better documentation is coming soon):
263
263
 
264
- ```
265
-
266
- {
267
- "start": "a", // optionally specify the start node (defaults to jobs[0])
268
- "jobs": [
264
+ ```json
269
265
  {
270
- "id": "a",
271
- "expression": "fn((state) => state)", // code or a path
272
- "adaptor": "@openfn/language-common@1.75", // specifiy the adaptor to use (version optional)
273
- "data": {}, // optionally pre-populate the data object (this will be overriden by keys in in previous state)
274
- "configuration": {}, // Use this to pass credentials
275
- "next": {
276
- // This object defines which jobs to call next
277
- // All edges returning true will run
278
- // If there are no next edges, the workflow will end
279
- "b": true,
280
- "c": {
281
- "condition": "!state.error" // Not that this is an expression, not a function
266
+ "start": "a", // optionally specify the start node (defaults to jobs[0])
267
+ "jobs": [
268
+ {
269
+ "id": "a",
270
+ "expression": "fn((state) => state)", // code or a path
271
+ "adaptor": "@openfn/language-common@1.75", // specifiy the adaptor to use (version optional)
272
+ "data": {}, // optionally pre-populate the data object (this will be overriden by keys in in previous state)
273
+ "configuration": {}, // Use this to pass credentials
274
+ "next": {
275
+ // This object defines which jobs to call next
276
+ // All edges returning true will run
277
+ // If there are no next edges, the workflow will end
278
+ "b": true,
279
+ "c": {
280
+ "condition": "!state.error" // Not that this is an expression, not a function
281
+ }
282
+ }
283
+ }
284
+ ]
282
285
  }
283
- }
284
- },
285
- ]
286
- }
287
-
288
286
  ```
289
287
 
290
288
  ## Compilation
@@ -1083,16 +1083,32 @@ import path5 from "path";
1083
1083
  import fs3 from "node:fs/promises";
1084
1084
  import {
1085
1085
  getConfig as getConfig2,
1086
- getState,
1087
- mergeSpecIntoState,
1088
- getSpec
1086
+ getProject,
1087
+ getSpec,
1088
+ getStateFromProjectPayload
1089
1089
  } from "@openfn/deploy";
1090
1090
  async function pullHandler(options, logger) {
1091
1091
  try {
1092
1092
  assert_path_default(options.projectId);
1093
1093
  const config = mergeOverrides2(await getConfig2(options.configPath), options);
1094
- logger.always("Downloading project yaml and state from instance");
1095
- const state = await getState(config.statePath);
1094
+ logger.always("Downloading existing project state (as JSON) from the server.");
1095
+ const { data: project } = await getProject(config, options.projectId);
1096
+ if (!project) {
1097
+ logger.error("ERROR: Project not found.");
1098
+ logger.warn(
1099
+ "Please check the UUID and verify your endpoint and apiKey in your config."
1100
+ );
1101
+ process.exitCode = 1;
1102
+ process.exit(1);
1103
+ }
1104
+ const state = getStateFromProjectPayload(project);
1105
+ await fs3.writeFile(
1106
+ path5.resolve(config.statePath),
1107
+ JSON.stringify(state, null, 2)
1108
+ );
1109
+ logger.always(
1110
+ "Downloading the project spec (as YAML) from the server."
1111
+ );
1096
1112
  const url2 = new URL(
1097
1113
  `api/provision/yaml?id=${options.projectId}`,
1098
1114
  config.endpoint
@@ -1104,22 +1120,24 @@ async function pullHandler(options, logger) {
1104
1120
  Accept: "application/json"
1105
1121
  }
1106
1122
  });
1123
+ if (res.status != 200) {
1124
+ logger.error("ERROR: Project spec not retrieved.");
1125
+ logger.warn(
1126
+ "No YAML representation of this project could be retrieved from the server."
1127
+ );
1128
+ process.exitCode = 1;
1129
+ process.exit(1);
1130
+ }
1107
1131
  const resolvedPath = path5.resolve(config.specPath);
1108
1132
  logger.debug("reading spec from", resolvedPath);
1109
1133
  await fs3.writeFile(resolvedPath, res.body);
1110
- const spec = await getSpec(config.specPath);
1111
- logger.debug("validated spec: ", spec);
1134
+ const spec = await getSpec(resolvedPath);
1112
1135
  if (spec.errors.length > 0) {
1113
1136
  logger.error("ERROR: invalid spec");
1114
1137
  logger.error(spec.errors);
1115
1138
  process.exitCode = 1;
1116
1139
  process.exit(1);
1117
1140
  }
1118
- const nextState = mergeSpecIntoState(state, spec.doc);
1119
- await fs3.writeFile(
1120
- path5.resolve(config.statePath),
1121
- JSON.stringify(nextState, null, 2)
1122
- );
1123
1141
  logger.success("Project pulled successfully");
1124
1142
  process.exitCode = 0;
1125
1143
  return true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openfn/cli",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "CLI devtools for the openfn toolchain.",
5
5
  "engines": {
6
6
  "node": ">=18",
@@ -44,11 +44,11 @@
44
44
  "rimraf": "^3.0.2",
45
45
  "treeify": "^1.1.0",
46
46
  "yargs": "^17.7.2",
47
- "@openfn/compiler": "0.0.36",
48
- "@openfn/deploy": "0.2.6",
47
+ "@openfn/compiler": "0.0.37",
48
+ "@openfn/deploy": "0.2.8",
49
49
  "@openfn/describe-package": "0.0.18",
50
- "@openfn/logger": "0.0.17",
51
- "@openfn/runtime": "0.0.30"
50
+ "@openfn/logger": "0.0.18",
51
+ "@openfn/runtime": "0.0.32"
52
52
  },
53
53
  "files": [
54
54
  "dist",