farseer-cli 1.12.0 → 1.14.1
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 +51 -18
- package/dist/commands/login.js +60 -26
- package/dist/commands/login.js.map +2 -2
- package/dist/commands/logout.js +37 -12
- package/dist/commands/logout.js.map +3 -3
- package/dist/commands/pipeline.js +158 -0
- package/dist/commands/pipeline.js.map +7 -0
- package/dist/commands/run.js +10 -27
- package/dist/commands/run.js.map +2 -2
- package/dist/commands/variables.js +17 -8
- package/dist/commands/variables.js.map +2 -2
- package/dist/commands/whoami.js +10 -14
- package/dist/commands/whoami.js.map +2 -2
- package/dist/index.js +40 -46
- package/dist/index.js.map +2 -2
- package/dist/mcp/prompts/workflows.js +13 -68
- package/dist/mcp/prompts/workflows.js.map +2 -2
- package/dist/mcp/resources/documentation.js +14 -0
- package/dist/mcp/resources/documentation.js.map +2 -2
- package/dist/mcp/server.js +14 -2
- package/dist/mcp/server.js.map +2 -2
- package/dist/mcp/skills.js +59 -0
- package/dist/mcp/skills.js.map +7 -0
- package/dist/mcp/tools/appTools.js +4 -0
- package/dist/mcp/tools/appTools.js.map +2 -2
- package/dist/mcp/tools/authTools.js +5 -2
- package/dist/mcp/tools/authTools.js.map +2 -2
- package/dist/mcp/tools/dataTools.js +2 -0
- package/dist/mcp/tools/dataTools.js.map +2 -2
- package/dist/mcp/tools/modelTools.js +6 -41
- package/dist/mcp/tools/modelTools.js.map +2 -2
- package/dist/mcp/tools/pipelineContract.js +317 -0
- package/dist/mcp/tools/pipelineContract.js.map +7 -0
- package/dist/mcp/tools/pipelineTools.js +111 -0
- package/dist/mcp/tools/pipelineTools.js.map +7 -0
- package/dist/mcp/tools/runTools.js +7 -18
- package/dist/mcp/tools/runTools.js.map +2 -2
- package/dist/mcp/tools/syncTools.js +4 -0
- package/dist/mcp/tools/syncTools.js.map +2 -2
- package/dist/mcp/utils/helpers.js +16 -6
- package/dist/mcp/utils/helpers.js.map +3 -3
- package/dist/mcp/utils/session.js +14 -9
- package/dist/mcp/utils/session.js.map +2 -2
- package/dist/pipeline/compatibility.js +53 -0
- package/dist/pipeline/compatibility.js.map +7 -0
- package/dist/pipeline/connect.js +139 -0
- package/dist/pipeline/connect.js.map +7 -0
- package/dist/pipeline/create.js +158 -0
- package/dist/pipeline/create.js.map +7 -0
- package/dist/pipeline/errors.js +45 -0
- package/dist/pipeline/errors.js.map +7 -0
- package/dist/pipeline/generated-reference.json +115 -0
- package/dist/pipeline/guide.js +33 -0
- package/dist/pipeline/guide.js.map +7 -0
- package/dist/pipeline/init.js +204 -0
- package/dist/pipeline/init.js.map +7 -0
- package/dist/pipeline/operations.js +103 -0
- package/dist/pipeline/operations.js.map +7 -0
- package/dist/pipeline/query.js +103 -0
- package/dist/pipeline/query.js.map +7 -0
- package/dist/pipeline/queryWorker.js +119 -0
- package/dist/pipeline/queryWorker.js.map +7 -0
- package/dist/pipeline/readiness.js +55 -0
- package/dist/pipeline/readiness.js.map +7 -0
- package/dist/pipeline/reference.js +72 -0
- package/dist/pipeline/reference.js.map +7 -0
- package/dist/pipeline/requests.js +122 -0
- package/dist/pipeline/requests.js.map +7 -0
- package/dist/pipeline/runArguments.js +68 -0
- package/dist/pipeline/runArguments.js.map +7 -0
- package/dist/pipeline/runtime.js +105 -0
- package/dist/pipeline/runtime.js.map +7 -0
- package/dist/pipeline/service.js +967 -0
- package/dist/pipeline/service.js.map +7 -0
- package/dist/services/agentApprovalFetch.js +86 -0
- package/dist/services/agentApprovalFetch.js.map +7 -0
- package/dist/services/authErrors.js +2 -2
- package/dist/services/authErrors.js.map +2 -2
- package/dist/services/configService.js +74 -9
- package/dist/services/configService.js.map +2 -2
- package/dist/services/credentials.js +12 -7
- package/dist/services/credentials.js.map +2 -2
- package/dist/services/farseerService.js +94 -39
- package/dist/services/farseerService.js.map +2 -2
- package/dist/services/preflight.js +7 -2
- package/dist/services/preflight.js.map +2 -2
- package/dist/services/realms.js +67 -0
- package/dist/services/realms.js.map +7 -0
- package/dist/services/syncService.js +6 -0
- package/dist/services/syncService.js.map +2 -2
- package/dist/skills/pipeline.js +71 -0
- package/dist/skills/pipeline.js.map +7 -0
- package/dist/utils/helpers.js +2 -1
- package/dist/utils/helpers.js.map +2 -2
- package/dist/utils/variableValues.js +78 -0
- package/dist/utils/variableValues.js.map +7 -0
- package/docs/pipeline-client-guide.md +67 -0
- package/docs/pipeline-reference.md +2064 -0
- package/package.json +5 -1
- package/skills/pipeline-authoring/SKILL.md +95 -0
- package/skills/pipeline-authoring/practices.md +325 -0
package/README.md
CHANGED
|
@@ -180,6 +180,16 @@ Either way the organisation is checked against the tenant before any tool runs,
|
|
|
180
180
|
|
|
181
181
|
## Authentication
|
|
182
182
|
|
|
183
|
+
### Agent sandbox credentials
|
|
184
|
+
|
|
185
|
+
Inside the Farseer agent sandbox, each turn passes a short-lived agent key (`agent1.` prefix)
|
|
186
|
+
in `FARSEER_API_KEY`, together with `FARSEER_URL` (backend origin, e.g.
|
|
187
|
+
`http://localhost:3000`) and `FARSEER_TENANT`. CLI commands and `farseer mcp-server` then
|
|
188
|
+
use that key without saving it, ahead of saved keys and browser logins. A missing URL or
|
|
189
|
+
tenant, or a request for another tenant, is refused. Any other `FARSEER_API_KEY`, such as
|
|
190
|
+
the one app scripts and the SDK use, does not change how the CLI logs in. An MCP process
|
|
191
|
+
reads its credentials at launch: restart it when the key rotates.
|
|
192
|
+
|
|
183
193
|
Farseer CLI supports two authentication methods:
|
|
184
194
|
|
|
185
195
|
### Browser Login (JWT) - Recommended
|
|
@@ -188,15 +198,26 @@ Farseer CLI supports two authentication methods:
|
|
|
188
198
|
# Default realm (master)
|
|
189
199
|
farseer login
|
|
190
200
|
|
|
191
|
-
#
|
|
201
|
+
# An organisation with its own realm: the CLI looks the realm up
|
|
202
|
+
farseer login --org acme
|
|
203
|
+
|
|
204
|
+
# Or name the realm directly (case-insensitive)
|
|
192
205
|
farseer login --realm acme
|
|
206
|
+
|
|
207
|
+
# Farseer staff, into a customer realm with a Farseer account
|
|
208
|
+
farseer login --org acme --idp-hint farseer-master
|
|
193
209
|
```
|
|
194
210
|
|
|
195
211
|
Opens Keycloak login in browser. Features:
|
|
196
212
|
- Automatic token refresh
|
|
197
|
-
-
|
|
213
|
+
- One login per realm, kept side by side; each command uses the one for its organisation's realm
|
|
214
|
+
- Access to all tenants you have permissions for in that realm
|
|
198
215
|
- Full functionality (scripts + apps)
|
|
199
216
|
|
|
217
|
+
A customer realm's login opens the organisation's own sign-in, as the web app does. Farseer staff have no password there and go through the `farseer-master` provider instead; if the browser has no Farseer session yet, the same tab asks for the Farseer login first.
|
|
218
|
+
|
|
219
|
+
`farseer logout` ends every browser login (`--realm <realm>` for one) at Keycloak and removes it locally.
|
|
220
|
+
|
|
200
221
|
### API Key Login
|
|
201
222
|
|
|
202
223
|
```bash
|
|
@@ -747,9 +768,9 @@ AI assistants can read comprehensive documentation:
|
|
|
747
768
|
|
|
748
769
|
Guided workflows for common tasks:
|
|
749
770
|
- **setup_new_tenant** - Setup new tenant from scratch
|
|
750
|
-
- **create_new_app** - Create
|
|
771
|
+
- **create_new_app** - Create a non-pipeline app; routes new pipelines to Simple Pipelines
|
|
751
772
|
- **understand_model** - Explore data model
|
|
752
|
-
- **write_import_script** -
|
|
773
|
+
- **write_import_script** - Maintain an existing TypeScript import or author a new Simple Pipeline
|
|
753
774
|
- **copy_app** - Copy and modify existing app
|
|
754
775
|
- **debug_sync_issues** - Troubleshoot sync problems
|
|
755
776
|
|
|
@@ -758,14 +779,19 @@ Guided workflows for common tasks:
|
|
|
758
779
|
**List apps:**
|
|
759
780
|
> "Show me all my Farseer apps"
|
|
760
781
|
|
|
761
|
-
**Create
|
|
762
|
-
> "Create a
|
|
782
|
+
**Create a pipeline:**
|
|
783
|
+
> "Create a pipeline for Sales Amount that reads from CSV"
|
|
763
784
|
|
|
764
785
|
The AI will:
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
786
|
+
|
|
787
|
+
1. Inspect existing apps and source, and check what dimensions Sales Amount has
|
|
788
|
+
2. Author the new pipeline with Simple Pipelines
|
|
789
|
+
3. Push its source, run it and inspect the result
|
|
790
|
+
|
|
791
|
+
**Maintain an existing TypeScript app:**
|
|
792
|
+
> "Fix the date mapping in our existing Sales import"
|
|
793
|
+
|
|
794
|
+
The AI uses the existing app tools to inspect, run, debug and make targeted fixes in TypeScript. It preserves the app's implementation and configuration; migration to Simple Pipelines requires an explicit migration request. New repeatable pipelines use Simple Pipelines, even when TypeScript is requested. This policy applies per app on tenants with both implementations.
|
|
769
795
|
|
|
770
796
|
**Debug issues:**
|
|
771
797
|
> "Pull latest changes and show me what's different"
|
|
@@ -871,11 +897,16 @@ settings are untouched and the next `pull` on this version puts the keys back.
|
|
|
871
897
|
"basePath": "https://my-org.farseer.io/api/v3"
|
|
872
898
|
}
|
|
873
899
|
},
|
|
874
|
-
"
|
|
875
|
-
"
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
900
|
+
"userAuths": {
|
|
901
|
+
"master": {
|
|
902
|
+
"accessToken": "...",
|
|
903
|
+
"refreshToken": "...",
|
|
904
|
+
"expiresAt": "2025-01-28T10:00:00Z",
|
|
905
|
+
"realm": "master"
|
|
906
|
+
}
|
|
907
|
+
},
|
|
908
|
+
"organisationRealms": {
|
|
909
|
+
"acme": "ACME"
|
|
879
910
|
},
|
|
880
911
|
"tenantOrgMapping": {
|
|
881
912
|
"my-tenant": "my-org"
|
|
@@ -1005,9 +1036,11 @@ farseer app configure "My App" --entrypoint index.ts
|
|
|
1005
1036
|
### Login Issues with Different Realm
|
|
1006
1037
|
|
|
1007
1038
|
```bash
|
|
1008
|
-
#
|
|
1009
|
-
farseer login --
|
|
1010
|
-
|
|
1039
|
+
# Let the organisation name its realm
|
|
1040
|
+
farseer login --org acme
|
|
1041
|
+
|
|
1042
|
+
# Farseer staff: a customer realm's own form has no password for you
|
|
1043
|
+
farseer login --org acme --idp-hint farseer-master
|
|
1011
1044
|
```
|
|
1012
1045
|
|
|
1013
1046
|
---
|
package/dist/commands/login.js
CHANGED
|
@@ -34,41 +34,44 @@ module.exports = __toCommonJS(login_exports);
|
|
|
34
34
|
var import_inquirer = __toESM(require("inquirer"));
|
|
35
35
|
var import_logger = require("../utils/logger");
|
|
36
36
|
var import_configService = require("../services/configService");
|
|
37
|
+
var import_realms = require("../services/realms");
|
|
37
38
|
var import_farseerService = require("../services/farseerService");
|
|
38
39
|
var import_helpers = require("../utils/helpers");
|
|
40
|
+
const MASTER_IDP_HINT = "farseer-master";
|
|
39
41
|
function registerLoginCommand(program) {
|
|
40
|
-
program.command("login").description("Login to Farseer (opens browser or use --api-key)").option("--api-key", "Login using API key instead of browser").option("--realm <realm>", "Keycloak realm to use (default: master)").
|
|
42
|
+
program.command("login").description("Login to Farseer (opens browser or use --api-key)").option("--api-key", "Login using API key instead of browser").option("--org <organisation>", "Log in to the Keycloak realm of this organisation's tenants (e.g. jgl)").option("--realm <realm>", "Keycloak realm to use (default: master)").option(
|
|
43
|
+
"--idp-hint <hint>",
|
|
44
|
+
`Identity provider to log in through (default: the organisation's own; Farseer staff: "${MASTER_IDP_HINT}")`
|
|
45
|
+
).option("--no-idp-hint", "Use the realm's own login form, ignoring the organisation's identity provider").action(async (options) => {
|
|
41
46
|
if (options.apiKey) {
|
|
42
47
|
await loginWithApiKey();
|
|
43
48
|
} else {
|
|
44
|
-
await loginViaBrowser(options
|
|
49
|
+
await loginViaBrowser(options);
|
|
45
50
|
}
|
|
46
51
|
});
|
|
47
52
|
}
|
|
48
|
-
async function loginViaBrowser(realm) {
|
|
49
|
-
let realmToUse = realm || "master";
|
|
53
|
+
async function loginViaBrowser({ org, realm, idpHint }) {
|
|
50
54
|
import_logger.logger.header("Farseer Login");
|
|
51
|
-
if (realm) {
|
|
52
|
-
import_logger.logger.
|
|
53
|
-
|
|
54
|
-
if (!resolved) {
|
|
55
|
-
import_logger.logger.error(`Realm "${realm}" not found on Keycloak server.`);
|
|
56
|
-
import_logger.logger.dim("Check the realm name and try again (realm names are case-sensitive).");
|
|
57
|
-
import_logger.logger.dim("Example: farseer login --realm JGL");
|
|
58
|
-
process.exit(1);
|
|
59
|
-
}
|
|
60
|
-
realmToUse = resolved;
|
|
61
|
-
if (resolved !== realm) {
|
|
62
|
-
import_logger.logger.info(`Realm resolved to: ${resolved}`);
|
|
63
|
-
} else {
|
|
64
|
-
import_logger.logger.info(`Using realm: ${realmToUse}`);
|
|
65
|
-
}
|
|
55
|
+
if (org && realm) {
|
|
56
|
+
import_logger.logger.error("Pass either --org or --realm, not both.");
|
|
57
|
+
process.exit(1);
|
|
66
58
|
}
|
|
59
|
+
const target = org ? await realmOfOrganisationOrExit(org) : { realm: realm ? await resolveRealmOrExit(realm) : import_configService.DEFAULT_REALM };
|
|
60
|
+
const realmToUse = target.realm;
|
|
61
|
+
const hintToUse = resolveIdpHint(idpHint, target.idpHint);
|
|
67
62
|
import_logger.logger.info("Opening browser for login...");
|
|
68
63
|
import_logger.logger.dim("Waiting for authentication (timeout: 5 minutes)...");
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
64
|
+
if (hintToUse) {
|
|
65
|
+
import_logger.logger.dim(`Identity provider: ${hintToUse}`);
|
|
66
|
+
} else if (realmToUse !== import_configService.DEFAULT_REALM) {
|
|
67
|
+
import_logger.logger.dim(`Farseer staff: add --idp-hint ${MASTER_IDP_HINT} to log in with your Farseer account.`);
|
|
68
|
+
}
|
|
69
|
+
const result = await (0, import_farseerService.loginWithBrowser)(realmToUse, {
|
|
70
|
+
idpHint: hintToUse,
|
|
71
|
+
viaMasterSession: hintToUse === MASTER_IDP_HINT
|
|
72
|
+
});
|
|
73
|
+
if (!result.ok) {
|
|
74
|
+
import_logger.logger.error(`Login failed or timed out${result.error ? ` (${result.error})` : ""}.`);
|
|
72
75
|
import_logger.logger.dim("Try using --api-key for manual API key login.");
|
|
73
76
|
process.exit(1);
|
|
74
77
|
}
|
|
@@ -80,13 +83,44 @@ async function loginViaBrowser(realm) {
|
|
|
80
83
|
realm: realmToUse
|
|
81
84
|
});
|
|
82
85
|
import_logger.logger.success("Login successful!");
|
|
86
|
+
import_logger.logger.dim(`Realm: ${realmToUse}`);
|
|
83
87
|
import_logger.logger.dim(`Token expires at: ${expiresAt.toLocaleString()}`);
|
|
84
|
-
|
|
85
|
-
import_logger.logger.dim(`Realm: ${realmToUse}`);
|
|
86
|
-
}
|
|
87
|
-
import_logger.logger.dim("You can now access any tenant you have permissions for.");
|
|
88
|
+
import_logger.logger.dim(`You can now access any tenant in realm "${realmToUse}" you have permissions for.`);
|
|
88
89
|
process.exit(0);
|
|
89
90
|
}
|
|
91
|
+
async function realmOfOrganisationOrExit(organisation) {
|
|
92
|
+
import_logger.logger.info(`Looking up the realm of organisation: ${organisation}...`);
|
|
93
|
+
const config = await (0, import_realms.fetchOrganisationKeycloakConfig)(organisation);
|
|
94
|
+
if (!config) {
|
|
95
|
+
import_logger.logger.error(`Could not read the login configuration of "${organisation}".`);
|
|
96
|
+
import_logger.logger.dim(`Check that https://${organisation}.farseer.io is reachable, or pass --realm <realm> instead.`);
|
|
97
|
+
process.exit(1);
|
|
98
|
+
}
|
|
99
|
+
(0, import_configService.saveOrganisationRealm)(organisation, config.realm);
|
|
100
|
+
import_logger.logger.info(`Using realm: ${config.realm}`);
|
|
101
|
+
return config;
|
|
102
|
+
}
|
|
103
|
+
async function resolveRealmOrExit(realm) {
|
|
104
|
+
import_logger.logger.info(`Resolving realm: ${realm}...`);
|
|
105
|
+
const resolved = await (0, import_farseerService.resolveRealm)(realm);
|
|
106
|
+
if (!resolved) {
|
|
107
|
+
import_logger.logger.error(`Realm "${realm}" not found on Keycloak server.`);
|
|
108
|
+
import_logger.logger.dim("Check the realm name and try again (realm names are case-sensitive).");
|
|
109
|
+
import_logger.logger.dim("Or let the organisation pick it: farseer login --org jgl");
|
|
110
|
+
process.exit(1);
|
|
111
|
+
}
|
|
112
|
+
import_logger.logger.info(resolved !== realm ? `Realm resolved to: ${resolved}` : `Using realm: ${resolved}`);
|
|
113
|
+
return resolved;
|
|
114
|
+
}
|
|
115
|
+
function resolveIdpHint(idpHint, organisationHint) {
|
|
116
|
+
if (typeof idpHint === "string") {
|
|
117
|
+
return idpHint;
|
|
118
|
+
}
|
|
119
|
+
if (idpHint === false) {
|
|
120
|
+
return void 0;
|
|
121
|
+
}
|
|
122
|
+
return organisationHint;
|
|
123
|
+
}
|
|
90
124
|
async function loginWithApiKey() {
|
|
91
125
|
import_logger.logger.header("Farseer Login (API Key)");
|
|
92
126
|
const answers = await import_inquirer.default.prompt([
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/commands/login.ts"],
|
|
4
|
-
"sourcesContent": ["import { Command } from 'commander';\nimport inquirer from 'inquirer';\nimport { logger } from '../utils/logger';\nimport {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,sBAAqB;AACrB,oBAAuB;AACvB,
|
|
4
|
+
"sourcesContent": ["import { Command } from 'commander';\nimport inquirer from 'inquirer';\nimport { logger } from '../utils/logger';\nimport {\n setCredential,\n setUserAuth,\n generateBasePath,\n saveOrganisationRealm,\n ApiKeyCredential,\n DEFAULT_REALM,\n} from '../services/configService';\nimport { fetchOrganisationKeycloakConfig, type OrganisationKeycloakConfig } from '../services/realms';\nimport { loginWithBrowser, resolveRealm, FarseerService } from '../services/farseerService';\nimport { connectionFailureMessage } from '../utils/helpers';\n\n/** Keycloak identity provider that brokers a master-realm account into a customer realm. */\nconst MASTER_IDP_HINT = 'farseer-master';\n\nexport function registerLoginCommand(program: Command): void {\n program\n .command('login')\n .description('Login to Farseer (opens browser or use --api-key)')\n .option('--api-key', 'Login using API key instead of browser')\n .option('--org <organisation>', \"Log in to the Keycloak realm of this organisation's tenants (e.g. jgl)\")\n .option('--realm <realm>', 'Keycloak realm to use (default: master)')\n .option(\n '--idp-hint <hint>',\n `Identity provider to log in through (default: the organisation's own; Farseer staff: \"${MASTER_IDP_HINT}\")`,\n )\n .option('--no-idp-hint', \"Use the realm's own login form, ignoring the organisation's identity provider\")\n .action(async (options) => {\n if (options.apiKey) {\n await loginWithApiKey();\n } else {\n await loginViaBrowser(options);\n }\n });\n}\n\ninterface BrowserLoginOptions {\n org?: string;\n realm?: string;\n idpHint?: string | boolean;\n}\n\nasync function loginViaBrowser({ org, realm, idpHint }: BrowserLoginOptions): Promise<void> {\n logger.header('Farseer Login');\n\n if (org && realm) {\n logger.error('Pass either --org or --realm, not both.');\n process.exit(1);\n }\n\n const target = org\n ? await realmOfOrganisationOrExit(org)\n : { realm: realm ? await resolveRealmOrExit(realm) : DEFAULT_REALM };\n const realmToUse = target.realm;\n\n // Same default as the web app: the organisation's own provider. An @farseer.io\n // account has no password in a customer realm, so staff go through the\n // farseer-master broker instead, which federates their master-realm session.\n const hintToUse = resolveIdpHint(idpHint, target.idpHint);\n\n logger.info('Opening browser for login...');\n logger.dim('Waiting for authentication (timeout: 5 minutes)...');\n if (hintToUse) {\n logger.dim(`Identity provider: ${hintToUse}`);\n } else if (realmToUse !== DEFAULT_REALM) {\n logger.dim(`Farseer staff: add --idp-hint ${MASTER_IDP_HINT} to log in with your Farseer account.`);\n }\n\n const result = await loginWithBrowser(realmToUse, {\n idpHint: hintToUse,\n viaMasterSession: hintToUse === MASTER_IDP_HINT,\n });\n\n if (!result.ok) {\n logger.error(`Login failed or timed out${result.error ? ` (${result.error})` : ''}.`);\n logger.dim('Try using --api-key for manual API key login.');\n process.exit(1);\n }\n\n const expiresAt = new Date(Date.now() + result.expiresIn * 1000);\n\n setUserAuth({\n accessToken: result.accessToken,\n refreshToken: result.refreshToken,\n expiresAt: expiresAt.toISOString(),\n realm: realmToUse,\n });\n\n logger.success('Login successful!');\n logger.dim(`Realm: ${realmToUse}`);\n logger.dim(`Token expires at: ${expiresAt.toLocaleString()}`);\n logger.dim(`You can now access any tenant in realm \"${realmToUse}\" you have permissions for.`);\n process.exit(0);\n}\n\nasync function realmOfOrganisationOrExit(organisation: string): Promise<OrganisationKeycloakConfig> {\n logger.info(`Looking up the realm of organisation: ${organisation}...`);\n const config = await fetchOrganisationKeycloakConfig(organisation);\n if (!config) {\n logger.error(`Could not read the login configuration of \"${organisation}\".`);\n logger.dim(`Check that https://${organisation}.farseer.io is reachable, or pass --realm <realm> instead.`);\n process.exit(1);\n }\n saveOrganisationRealm(organisation, config.realm);\n logger.info(`Using realm: ${config.realm}`);\n return config;\n}\n\n/** Realm names are case-sensitive, and people type them from the org name. */\nasync function resolveRealmOrExit(realm: string): Promise<string> {\n logger.info(`Resolving realm: ${realm}...`);\n const resolved = await resolveRealm(realm);\n if (!resolved) {\n logger.error(`Realm \"${realm}\" not found on Keycloak server.`);\n logger.dim('Check the realm name and try again (realm names are case-sensitive).');\n logger.dim('Or let the organisation pick it: farseer login --org jgl');\n process.exit(1);\n }\n logger.info(resolved !== realm ? `Realm resolved to: ${resolved}` : `Using realm: ${resolved}`);\n return resolved;\n}\n\n/**\n * `--idp-hint <hint>` picks the provider, `--no-idp-hint` forces the realm's own form\n * (commander gives us `false` for it), and anything else falls back to the\n * organisation's own provider \u2014 none with `--realm`, which names no organisation.\n */\nfunction resolveIdpHint(idpHint: string | boolean | undefined, organisationHint?: string): string | undefined {\n if (typeof idpHint === 'string') {\n return idpHint;\n }\n if (idpHint === false) {\n return undefined;\n }\n return organisationHint;\n}\n\nasync function loginWithApiKey(): Promise<void> {\n logger.header('Farseer Login (API Key)');\n\n const answers = await inquirer.prompt([\n {\n type: 'input',\n name: 'tenant',\n message: 'Tenant ID (e.g., tthotels):',\n validate: (input) => {\n if (!input || input.trim() === '') {\n return 'Tenant ID is required';\n }\n return true;\n },\n },\n {\n type: 'input',\n name: 'organisation',\n message: 'Organisation (leave empty if same as tenant):',\n },\n {\n type: 'password',\n name: 'apiKey',\n message: 'API Key:',\n mask: '*',\n validate: (input) => {\n if (!input || input.trim() === '') {\n return 'API Key is required';\n }\n return true;\n },\n },\n ]);\n\n const tenant = answers.tenant.trim();\n const organisation = answers.organisation.trim() || tenant;\n const apiKey = answers.apiKey.trim();\n const basePath = generateBasePath(organisation);\n\n logger.info('Testing connection...');\n\n const credential: ApiKeyCredential = {\n type: 'apiKey',\n tenantId: tenant,\n apiKey: apiKey,\n basePath: basePath,\n };\n\n const service = new FarseerService({ kind: 'apiKey', credential });\n const connection = await service.checkConnection();\n\n if (!connection.ok) {\n logger.error(connectionFailureMessage(connection.reason, basePath, tenant));\n logger.dim(connection.message);\n process.exit(1);\n }\n\n setCredential(tenant, credential);\n\n logger.success(`Successfully connected to ${tenant}!`);\n logger.dim(`Credentials saved for tenant: ${tenant}`);\n logger.dim(`Base path: ${basePath}`);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,sBAAqB;AACrB,oBAAuB;AACvB,2BAOO;AACP,oBAAiF;AACjF,4BAA+D;AAC/D,qBAAyC;AAGzC,MAAM,kBAAkB;AAEjB,SAAS,qBAAqB,SAAwB;AACzD,UACK,QAAQ,OAAO,EACf,YAAY,mDAAmD,EAC/D,OAAO,aAAa,wCAAwC,EAC5D,OAAO,wBAAwB,wEAAwE,EACvG,OAAO,mBAAmB,yCAAyC,EACnE;AAAA,IACG;AAAA,IACA,yFAAyF,eAAe;AAAA,EAC5G,EACC,OAAO,iBAAiB,+EAA+E,EACvG,OAAO,OAAO,YAAY;AACvB,QAAI,QAAQ,QAAQ;AAChB,YAAM,gBAAgB;AAAA,IAC1B,OAAO;AACH,YAAM,gBAAgB,OAAO;AAAA,IACjC;AAAA,EACJ,CAAC;AACT;AAQA,eAAe,gBAAgB,EAAE,KAAK,OAAO,QAAQ,GAAuC;AACxF,uBAAO,OAAO,eAAe;AAE7B,MAAI,OAAO,OAAO;AACd,yBAAO,MAAM,yCAAyC;AACtD,YAAQ,KAAK,CAAC;AAAA,EAClB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A,EACJ,CAAC;AAED,QAAM,SAAS,QAAQ,OAAO,KAAK;AACnC,QAAM,eAAe,QAAQ,aAAa,KAAK,KAAK;AACpD,QAAM,SAAS,QAAQ,OAAO,KAAK;AACnC,QAAM,eAAW,uCAAiB,YAAY;AAE9C,uBAAO,KAAK,uBAAuB;AAEnC,QAAM,aAA+B;AAAA,IACjC,MAAM;AAAA,IACN,UAAU;AAAA,IACV;AAAA,IACA;AAAA,EACJ;AAEA,QAAM,UAAU,IAAI,qCAAe,EAAE,MAAM,UAAU,WAAW,CAAC;AACjE,QAAM,aAAa,MAAM,QAAQ,gBAAgB;AAEjD,MAAI,CAAC,WAAW,IAAI;AAChB,yBAAO,UAAM,yCAAyB,WAAW,QAAQ,UAAU,MAAM,CAAC;AAC1E,yBAAO,IAAI,WAAW,OAAO;AAC7B,YAAQ,KAAK,CAAC;AAAA,EAClB;AAEA,0CAAc,QAAQ,UAAU;AAEhC,uBAAO,QAAQ,6BAA6B,MAAM,GAAG;AACrD,uBAAO,IAAI,iCAAiC,MAAM,EAAE;AACpD,uBAAO,IAAI,cAAc,QAAQ,EAAE;AACvC;",
|
|
6
6
|
"names": ["inquirer"]
|
|
7
7
|
}
|
package/dist/commands/logout.js
CHANGED
|
@@ -23,20 +23,22 @@ __export(logout_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(logout_exports);
|
|
24
24
|
var import_logger = require("../utils/logger");
|
|
25
25
|
var import_configService = require("../services/configService");
|
|
26
|
+
var import_farseerService = require("../services/farseerService");
|
|
26
27
|
function registerLogoutCommand(program) {
|
|
27
|
-
program.command("logout [tenant]").description("Logout from Farseer (remove credentials)").option("--all", "Remove all credentials").action(async (tenant, options) => {
|
|
28
|
+
program.command("logout [tenant]").description("Logout from Farseer (remove credentials)").option("--all", "Remove all credentials").option("--realm <realm>", "Clear only this realm's browser login").action(async (tenant, options) => {
|
|
28
29
|
if (options.all) {
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
if (tenants.length === 0) {
|
|
30
|
+
const tenants = Object.keys((0, import_configService.listCredentials)());
|
|
31
|
+
const realms2 = await logOutOfRealms(Object.entries((0, import_configService.listUserAuths)()));
|
|
32
|
+
if (tenants.length === 0 && realms2.length === 0) {
|
|
32
33
|
import_logger.logger.info("No credentials stored.");
|
|
33
34
|
return;
|
|
34
35
|
}
|
|
35
36
|
for (const t of tenants) {
|
|
36
37
|
(0, import_configService.removeCredential)(t);
|
|
37
38
|
}
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
import_logger.logger.success(
|
|
40
|
+
`Removed credentials for ${tenants.length} tenant(s) and ${realms2.length} browser login(s).`
|
|
41
|
+
);
|
|
40
42
|
return;
|
|
41
43
|
}
|
|
42
44
|
if (tenant) {
|
|
@@ -46,15 +48,38 @@ function registerLogoutCommand(program) {
|
|
|
46
48
|
} else {
|
|
47
49
|
import_logger.logger.warning(`No credentials found for tenant: ${tenant}`);
|
|
48
50
|
}
|
|
49
|
-
|
|
50
|
-
(0, import_configService.clearUserAuth)();
|
|
51
|
-
import_logger.logger.success("Logged out (user token cleared).");
|
|
52
|
-
import_logger.logger.dim(
|
|
53
|
-
'API key credentials are still stored. Use "farseer logout <tenant>" to remove specific ones.'
|
|
54
|
-
);
|
|
51
|
+
return;
|
|
55
52
|
}
|
|
53
|
+
const logins = Object.entries((0, import_configService.listUserAuths)());
|
|
54
|
+
const selected = options.realm ? logins.filter(([realm]) => sameRealm(realm, options.realm)) : logins;
|
|
55
|
+
if (selected.length === 0) {
|
|
56
|
+
if (options.realm) {
|
|
57
|
+
import_logger.logger.warning(`No browser login for realm: ${options.realm}`);
|
|
58
|
+
if (logins.length > 0) {
|
|
59
|
+
import_logger.logger.dim(`Logged in to: ${logins.map(([realm]) => realm).join(", ")}`);
|
|
60
|
+
}
|
|
61
|
+
} else {
|
|
62
|
+
import_logger.logger.info("Not logged in via browser.");
|
|
63
|
+
}
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const realms = await logOutOfRealms(selected);
|
|
67
|
+
import_logger.logger.success(`Logged out of ${realms.join(", ")} (user token cleared).`);
|
|
68
|
+
import_logger.logger.dim('API key credentials are still stored. Use "farseer logout <tenant>" to remove specific ones.');
|
|
56
69
|
});
|
|
57
70
|
}
|
|
71
|
+
function sameRealm(stored, typed) {
|
|
72
|
+
return stored.toLowerCase() === typed.toLowerCase();
|
|
73
|
+
}
|
|
74
|
+
async function logOutOfRealms(logins) {
|
|
75
|
+
for (const [realm, login] of logins) {
|
|
76
|
+
if (!await (0, import_farseerService.revokeRefreshToken)(realm, login.refreshToken)) {
|
|
77
|
+
import_logger.logger.dim(`Could not end the ${realm} session at Keycloak; it is cleared here only.`);
|
|
78
|
+
}
|
|
79
|
+
(0, import_configService.clearUserAuth)(realm);
|
|
80
|
+
}
|
|
81
|
+
return logins.map(([realm]) => realm);
|
|
82
|
+
}
|
|
58
83
|
// Annotate the CommonJS export names for ESM import in node:
|
|
59
84
|
0 && (module.exports = {
|
|
60
85
|
registerLogoutCommand
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/commands/logout.ts"],
|
|
4
|
-
"sourcesContent": ["import { Command } from 'commander';\nimport { logger } from '../utils/logger';\nimport {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAAuB;AACvB,
|
|
6
|
-
"names": []
|
|
4
|
+
"sourcesContent": ["import { Command } from 'commander';\nimport { logger } from '../utils/logger';\nimport {\n removeCredential,\n clearUserAuth,\n listCredentials,\n listUserAuths,\n type UserAuth,\n} from '../services/configService';\nimport { revokeRefreshToken } from '../services/farseerService';\n\nexport function registerLogoutCommand(program: Command): void {\n program\n .command('logout [tenant]')\n .description('Logout from Farseer (remove credentials)')\n .option('--all', 'Remove all credentials')\n .option('--realm <realm>', \"Clear only this realm's browser login\")\n .action(async (tenant, options) => {\n if (options.all) {\n // Remove all credentials\n const tenants = Object.keys(listCredentials());\n const realms = await logOutOfRealms(Object.entries(listUserAuths()));\n\n if (tenants.length === 0 && realms.length === 0) {\n logger.info('No credentials stored.');\n return;\n }\n\n for (const t of tenants) {\n removeCredential(t);\n }\n\n logger.success(\n `Removed credentials for ${tenants.length} tenant(s) and ${realms.length} browser login(s).`,\n );\n return;\n }\n\n if (tenant) {\n // Remove specific tenant\n const removed = removeCredential(tenant);\n if (removed) {\n logger.success(`Removed credentials for tenant: ${tenant}`);\n } else {\n logger.warning(`No credentials found for tenant: ${tenant}`);\n }\n return;\n }\n\n // Remove browser logins: one realm's, or all of them\n const logins = Object.entries(listUserAuths());\n const selected = options.realm ? logins.filter(([realm]) => sameRealm(realm, options.realm)) : logins;\n\n if (selected.length === 0) {\n if (options.realm) {\n logger.warning(`No browser login for realm: ${options.realm}`);\n if (logins.length > 0) {\n logger.dim(`Logged in to: ${logins.map(([realm]) => realm).join(', ')}`);\n }\n } else {\n logger.info('Not logged in via browser.');\n }\n return;\n }\n\n const realms = await logOutOfRealms(selected);\n logger.success(`Logged out of ${realms.join(', ')} (user token cleared).`);\n logger.dim('API key credentials are still stored. Use \"farseer logout <tenant>\" to remove specific ones.');\n });\n}\n\n/**\n * Realm names are case-sensitive in Keycloak, but people type them from the\n * organisation name \u2014 `login --realm jgl` itself resolves to `JGL`.\n */\nfunction sameRealm(stored: string, typed: string): boolean {\n return stored.toLowerCase() === typed.toLowerCase();\n}\n\n/** Ends each session at Keycloak, then clears it here whatever Keycloak said. */\nasync function logOutOfRealms(logins: [string, UserAuth][]): Promise<string[]> {\n for (const [realm, login] of logins) {\n if (!(await revokeRefreshToken(realm, login.refreshToken))) {\n logger.dim(`Could not end the ${realm} session at Keycloak; it is cleared here only.`);\n }\n clearUserAuth(realm);\n }\n return logins.map(([realm]) => realm);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAAuB;AACvB,2BAMO;AACP,4BAAmC;AA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M,SAAS,MAAM,eAAe,QAAQ;AAC5C,yBAAO,QAAQ,iBAAiB,OAAO,KAAK,IAAI,CAAC,wBAAwB;AACzE,yBAAO,IAAI,8FAA8F;AAAA,EAC7G,CAAC;AACT;AAMA,SAAS,UAAU,QAAgB,OAAwB;AACvD,SAAO,OAAO,YAAY,MAAM,MAAM,YAAY;AACtD;AAGA,eAAe,eAAe,QAAiD;AAC3E,aAAW,CAAC,OAAO,KAAK,KAAK,QAAQ;AACjC,QAAI,CAAE,UAAM,0CAAmB,OAAO,MAAM,YAAY,GAAI;AACxD,2BAAO,IAAI,qBAAqB,KAAK,gDAAgD;AAAA,IACzF;AACA,4CAAc,KAAK;AAAA,EACvB;AACA,SAAO,OAAO,IAAI,CAAC,CAAC,KAAK,MAAM,KAAK;AACxC;",
|
|
6
|
+
"names": ["realms"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var pipeline_exports = {};
|
|
30
|
+
__export(pipeline_exports, {
|
|
31
|
+
registerPipelineCommand: () => registerPipelineCommand,
|
|
32
|
+
shellError: () => shellError
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(pipeline_exports);
|
|
35
|
+
var fs = __toESM(require("fs"));
|
|
36
|
+
var import_connect = require("../pipeline/connect");
|
|
37
|
+
var import_operations = require("../pipeline/operations");
|
|
38
|
+
var import_reference = require("../pipeline/reference");
|
|
39
|
+
var import_errors = require("../pipeline/errors");
|
|
40
|
+
var import_service = require("../pipeline/service");
|
|
41
|
+
var import_requests = require("../pipeline/requests");
|
|
42
|
+
var import_pipeline = require("../skills/pipeline");
|
|
43
|
+
var import_helpers = require("../utils/helpers");
|
|
44
|
+
const PROFILE_HELP = "Prepared local profile (default: the one profile under tenant/.pipelines/)";
|
|
45
|
+
const PIPELINE_HELP = "Pipeline folder name; selects tenant/.pipelines/<name>.json";
|
|
46
|
+
function shellError(error) {
|
|
47
|
+
if (!(error instanceof import_errors.PipelineError)) return (0, import_service.redact)(String(error));
|
|
48
|
+
const next = error.nextAction ? `
|
|
49
|
+
Next: ${error.nextAction}` : "";
|
|
50
|
+
return (0, import_service.redact)(`Error: ${error.message}${next}`);
|
|
51
|
+
}
|
|
52
|
+
function registerPipelineCommand(program) {
|
|
53
|
+
const command = program.command("pipeline").description("Prepared pipeline authoring").configureHelp({ visibleCommands: (cmd) => [...cmd.commands] });
|
|
54
|
+
command.command("guide").option("--topic <name>", "method, practices, grammar, or a Pydantic model name", "method").option("--skill-path", "Print the bundled SKILL.md path for native skill installation").action((options) => {
|
|
55
|
+
try {
|
|
56
|
+
console.log(options.skillPath ? import_pipeline.PIPELINE_SKILL_PATH : (0, import_reference.pipelineGuide)(options.topic));
|
|
57
|
+
} catch (error) {
|
|
58
|
+
console.error(shellError(error));
|
|
59
|
+
process.exitCode = 1;
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
command.command("init <org> <tenant> [jobId]").description(
|
|
63
|
+
"Derive a local profile from a prepared job (changes nothing remotely), or with --new create a pipeline from nothing"
|
|
64
|
+
).option("--new <name>", "Create folder, job and profile for a new pipeline named after its folder").option("--workspace <dir>", "Tenant-relative source folder (default: the folder of the job main script)").option("--force", "Overwrite an existing profile for this job").action(async (org, tenant, jobId, options) => {
|
|
65
|
+
try {
|
|
66
|
+
const selection = {
|
|
67
|
+
organisation: org,
|
|
68
|
+
tenant,
|
|
69
|
+
jobId: jobId === void 0 ? void 0 : Number(jobId),
|
|
70
|
+
name: options.new,
|
|
71
|
+
workspace: options.workspace,
|
|
72
|
+
force: options.force
|
|
73
|
+
};
|
|
74
|
+
await (0, import_requests.withPipelineRequests)(async () => {
|
|
75
|
+
const result = await (0, import_operations.runPipelineInit)(
|
|
76
|
+
selection,
|
|
77
|
+
() => (0, import_connect.openPipelineConnection)(org, tenant),
|
|
78
|
+
(0, import_connect.pipelinePaths)(tenant)
|
|
79
|
+
);
|
|
80
|
+
console.log(JSON.stringify(result, null, 2));
|
|
81
|
+
});
|
|
82
|
+
} catch (error) {
|
|
83
|
+
console.error(shellError(error));
|
|
84
|
+
process.exitCode = 1;
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
command.command("runs [org] [tenant]").description("List the runs of the profile job, newest first").option("--profile <path>", PROFILE_HELP).option("--pipeline <name>", PIPELINE_HELP).option("--limit <number>", "Runs to show", "20").action(async (org, tenant, options) => {
|
|
88
|
+
try {
|
|
89
|
+
await (0, import_requests.withPipelineRequests)(async () => {
|
|
90
|
+
const checkout = (0, import_helpers.resolveTenantWithOrgMapping)(org, tenant);
|
|
91
|
+
const service = await (0, import_connect.connectPipeline)(checkout.organisation, checkout.tenant, {
|
|
92
|
+
profile: options.profile,
|
|
93
|
+
pipeline: options.pipeline
|
|
94
|
+
});
|
|
95
|
+
const result = await (0, import_operations.runPipelineOperation)(service, "runs", { limit: Number(options.limit) });
|
|
96
|
+
console.log(JSON.stringify(result, null, 2));
|
|
97
|
+
});
|
|
98
|
+
} catch (error) {
|
|
99
|
+
console.error(shellError(error));
|
|
100
|
+
process.exitCode = 1;
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
const operations = [...import_operations.PIPELINE_OPERATIONS.filter((o) => o !== "runs"), "recover", "unlock"];
|
|
104
|
+
for (const operation of operations) {
|
|
105
|
+
command.command(`${operation} <org> <tenant>`).option("--profile <path>", PROFILE_HELP).option("--pipeline <name>", PIPELINE_HELP).option("--uuid <uuid>", "Exact run UUID").option("--dataset-id <uuid>", "Dataset identifier").option("--version-id <uuid>", "Retained version identifier").option("--expected-current <uuid>", "Current version observed before restore").option("--import-id <number>", "Import ID from a run observation").option("--offset <number>", "Log offset", "0").option(
|
|
106
|
+
"--arg <NAME=value>",
|
|
107
|
+
"Job argument for this run, by name; repeat for several. Others keep their defaults",
|
|
108
|
+
(value, all) => [...all, value],
|
|
109
|
+
[]
|
|
110
|
+
).option("--bindings <json>", "Version bindings [{name,datasetId,versionId}]", "[]").option("--sql-file <path>", "Local inspection SQL file").action(async (org, tenant, options) => {
|
|
111
|
+
const controller = new AbortController();
|
|
112
|
+
const cancel = () => controller.abort();
|
|
113
|
+
process.once("SIGINT", cancel);
|
|
114
|
+
try {
|
|
115
|
+
await (0, import_requests.withPipelineRequests)(async () => {
|
|
116
|
+
const service = await (0, import_connect.connectPipeline)(org, tenant, {
|
|
117
|
+
profile: options.profile,
|
|
118
|
+
pipeline: options.pipeline
|
|
119
|
+
});
|
|
120
|
+
let result;
|
|
121
|
+
if (operation === "recover") result = await service.recover(options.uuid);
|
|
122
|
+
else if (operation === "unlock") result = service.unlockAbandonedOperation();
|
|
123
|
+
else {
|
|
124
|
+
if (operation === "query" && !options.sqlFile) throw new Error("--sql-file is required");
|
|
125
|
+
result = await (0, import_operations.runPipelineOperation)(
|
|
126
|
+
service,
|
|
127
|
+
operation,
|
|
128
|
+
{
|
|
129
|
+
uuid: options.uuid,
|
|
130
|
+
datasetId: options.datasetId,
|
|
131
|
+
versionId: options.versionId,
|
|
132
|
+
expectedCurrent: options.expectedCurrent,
|
|
133
|
+
importId: options.importId === void 0 ? void 0 : Number(options.importId),
|
|
134
|
+
offset: Number(options.offset),
|
|
135
|
+
args: options.arg,
|
|
136
|
+
bindings: JSON.parse(options.bindings),
|
|
137
|
+
sql: options.sqlFile && fs.readFileSync(options.sqlFile, "utf8")
|
|
138
|
+
},
|
|
139
|
+
controller.signal
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
console.log(JSON.stringify(result, null, 2));
|
|
143
|
+
}, controller.signal);
|
|
144
|
+
} catch (error) {
|
|
145
|
+
console.error(shellError(error));
|
|
146
|
+
process.exitCode = 1;
|
|
147
|
+
} finally {
|
|
148
|
+
process.removeListener("SIGINT", cancel);
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
154
|
+
0 && (module.exports = {
|
|
155
|
+
registerPipelineCommand,
|
|
156
|
+
shellError
|
|
157
|
+
});
|
|
158
|
+
//# sourceMappingURL=pipeline.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/commands/pipeline.ts"],
|
|
4
|
+
"sourcesContent": ["import { Command } from 'commander';\nimport * as fs from 'fs';\nimport { connectPipeline, openPipelineConnection, pipelinePaths } from '../pipeline/connect';\nimport { PIPELINE_OPERATIONS, runPipelineInit, runPipelineOperation } from '../pipeline/operations';\nimport { pipelineGuide } from '../pipeline/reference';\nimport { PipelineError } from '../pipeline/errors';\nimport { redact } from '../pipeline/service';\nimport { withPipelineRequests } from '../pipeline/requests';\nimport { PIPELINE_SKILL_PATH } from '../skills/pipeline';\nimport { resolveTenantWithOrgMapping } from '../utils/helpers';\n\nconst PROFILE_HELP = 'Prepared local profile (default: the one profile under tenant/.pipelines/)';\nconst PIPELINE_HELP = 'Pipeline folder name; selects tenant/.pipelines/<name>.json';\n\n/** What a shell user sees for a failed operation: the error, and the next step when it has one. */\nexport function shellError(error: unknown): string {\n if (!(error instanceof PipelineError)) return redact(String(error));\n const next = error.nextAction ? `\\nNext: ${error.nextAction}` : '';\n return redact(`Error: ${error.message}${next}`);\n}\n\nexport function registerPipelineCommand(program: Command) {\n const command = program\n .command('pipeline')\n .description('Prepared pipeline authoring')\n .configureHelp({ visibleCommands: (cmd) => [...cmd.commands] });\n command\n .command('guide')\n .option('--topic <name>', 'method, practices, grammar, or a Pydantic model name', 'method')\n .option('--skill-path', 'Print the bundled SKILL.md path for native skill installation')\n .action((options) => {\n try {\n console.log(options.skillPath ? PIPELINE_SKILL_PATH : pipelineGuide(options.topic));\n } catch (error) {\n console.error(shellError(error));\n process.exitCode = 1;\n }\n });\n command\n .command('init <org> <tenant> [jobId]')\n .description(\n 'Derive a local profile from a prepared job (changes nothing remotely), or with --new create a pipeline from nothing',\n )\n .option('--new <name>', 'Create folder, job and profile for a new pipeline named after its folder')\n .option('--workspace <dir>', 'Tenant-relative source folder (default: the folder of the job main script)')\n .option('--force', 'Overwrite an existing profile for this job')\n .action(async (org, tenant, jobId, options) => {\n try {\n const selection = {\n organisation: org,\n tenant,\n jobId: jobId === undefined ? undefined : Number(jobId),\n name: options.new,\n workspace: options.workspace,\n force: options.force,\n };\n await withPipelineRequests(async () => {\n const result = await runPipelineInit(\n selection,\n () => openPipelineConnection(org, tenant),\n pipelinePaths(tenant),\n );\n console.log(JSON.stringify(result, null, 2));\n });\n } catch (error) {\n console.error(shellError(error));\n process.exitCode = 1;\n }\n });\n command\n .command('runs [org] [tenant]')\n .description('List the runs of the profile job, newest first')\n .option('--profile <path>', PROFILE_HELP)\n .option('--pipeline <name>', PIPELINE_HELP)\n .option('--limit <number>', 'Runs to show', '20')\n .action(async (org, tenant, options) => {\n try {\n await withPipelineRequests(async () => {\n const checkout = resolveTenantWithOrgMapping(org, tenant);\n const service = await connectPipeline(checkout.organisation, checkout.tenant, {\n profile: options.profile,\n pipeline: options.pipeline,\n });\n const result = await runPipelineOperation(service, 'runs', { limit: Number(options.limit) });\n console.log(JSON.stringify(result, null, 2));\n });\n } catch (error) {\n console.error(shellError(error));\n process.exitCode = 1;\n }\n });\n // recover and unlock resolve local state after a crash; they are CLI-only on purpose.\n const operations = [...PIPELINE_OPERATIONS.filter((o) => o !== 'runs'), 'recover', 'unlock'] as const;\n for (const operation of operations) {\n command\n .command(`${operation} <org> <tenant>`)\n .option('--profile <path>', PROFILE_HELP)\n .option('--pipeline <name>', PIPELINE_HELP)\n .option('--uuid <uuid>', 'Exact run UUID')\n .option('--dataset-id <uuid>', 'Dataset identifier')\n .option('--version-id <uuid>', 'Retained version identifier')\n .option('--expected-current <uuid>', 'Current version observed before restore')\n .option('--import-id <number>', 'Import ID from a run observation')\n .option('--offset <number>', 'Log offset', '0')\n .option(\n '--arg <NAME=value>',\n 'Job argument for this run, by name; repeat for several. Others keep their defaults',\n (value: string, all: string[]) => [...all, value],\n [] as string[],\n )\n .option('--bindings <json>', 'Version bindings [{name,datasetId,versionId}]', '[]')\n .option('--sql-file <path>', 'Local inspection SQL file')\n .action(async (org, tenant, options) => {\n const controller = new AbortController();\n const cancel = () => controller.abort();\n process.once('SIGINT', cancel);\n try {\n await withPipelineRequests(async () => {\n const service = await connectPipeline(org, tenant, {\n profile: options.profile,\n pipeline: options.pipeline,\n });\n let result: unknown;\n if (operation === 'recover') result = await service.recover(options.uuid);\n else if (operation === 'unlock') result = service.unlockAbandonedOperation();\n else {\n if (operation === 'query' && !options.sqlFile) throw new Error('--sql-file is required');\n result = await runPipelineOperation(\n service,\n operation,\n {\n uuid: options.uuid,\n datasetId: options.datasetId,\n versionId: options.versionId,\n expectedCurrent: options.expectedCurrent,\n importId: options.importId === undefined ? undefined : Number(options.importId),\n offset: Number(options.offset),\n args: options.arg,\n bindings: JSON.parse(options.bindings),\n sql: options.sqlFile && fs.readFileSync(options.sqlFile, 'utf8'),\n },\n controller.signal,\n );\n }\n console.log(JSON.stringify(result, null, 2));\n }, controller.signal);\n } catch (error) {\n console.error(shellError(error));\n process.exitCode = 1;\n } finally {\n process.removeListener('SIGINT', cancel);\n }\n });\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,SAAoB;AACpB,qBAAuE;AACvE,wBAA2E;AAC3E,uBAA8B;AAC9B,oBAA8B;AAC9B,qBAAuB;AACvB,sBAAqC;AACrC,sBAAoC;AACpC,qBAA4C;AAE5C,MAAM,eAAe;AACrB,MAAM,gBAAgB;AAGf,SAAS,WAAW,OAAwB;AAC/C,MAAI,EAAE,iBAAiB,6BAAgB,YAAO,uBAAO,OAAO,KAAK,CAAC;AAClE,QAAM,OAAO,MAAM,aAAa;AAAA,QAAW,MAAM,UAAU,KAAK;AAChE,aAAO,uBAAO,UAAU,MAAM,OAAO,GAAG,IAAI,EAAE;AAClD;AAEO,SAAS,wBAAwB,SAAkB;AACtD,QAAM,UAAU,QACX,QAAQ,UAAU,EAClB,YAAY,6BAA6B,EACzC,cAAc,EAAE,iBAAiB,CAAC,QAAQ,CAAC,GAAG,IAAI,QAAQ,EAAE,CAAC;AAClE,UACK,QAAQ,OAAO,EACf,OAAO,kBAAkB,wDAAwD,QAAQ,EACzF,OAAO,gBAAgB,+DAA+D,EACtF,OAAO,CAAC,YAAY;AACj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