@fabricorg/experiments 0.6.5 → 0.7.0
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 +27 -2
- package/dist/bin/fx.cjs +443 -37
- package/dist/bin/fx.cjs.map +1 -1
- package/dist/bin/fx.js +444 -38
- package/dist/bin/fx.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
# Fabric Experiments CLI
|
|
2
2
|
|
|
3
|
-
`@fabricorg/experiments` installs the `fx` command for
|
|
3
|
+
`@fabricorg/experiments` installs the `fx` command for local and hosted Fabric Experiments workflows.
|
|
4
4
|
|
|
5
|
-
Fabric Experiments
|
|
5
|
+
Fabric Experiments unifies governed A/B experimentation, TypeScript BDD and live
|
|
6
|
+
testing for Databricks workloads, Quality Center evidence, and production release
|
|
7
|
+
policy.
|
|
6
8
|
|
|
7
9
|
## Install
|
|
8
10
|
|
|
@@ -21,6 +23,22 @@ fx --help
|
|
|
21
23
|
|
|
22
24
|
## Quickstart
|
|
23
25
|
|
|
26
|
+
For the hosted product, create a scoped API key in Studio and log in once:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
fx login --api-key fx_key_...
|
|
30
|
+
fx doctor
|
|
31
|
+
fx profile show
|
|
32
|
+
fx push experiments/
|
|
33
|
+
fx test publish reports/evidence.json
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
`fx login` discovers the current API and organization through the branded Studio
|
|
37
|
+
URL. It stores a private local profile; explicit flags and CI environment
|
|
38
|
+
variables remain supported.
|
|
39
|
+
|
|
40
|
+
For a local workspace:
|
|
41
|
+
|
|
24
42
|
In a project containing experiment YAML files:
|
|
25
43
|
|
|
26
44
|
```bash
|
|
@@ -37,11 +55,18 @@ fx kill homepage-cta --reason "Web Vitals regression"
|
|
|
37
55
|
fx validate <dir> Lint experiment YAML files in <dir>.
|
|
38
56
|
fx plan <dir> Show diff between YAML and live control plane.
|
|
39
57
|
fx apply <dir> Apply YAML to the control plane.
|
|
58
|
+
fx push <dir> Reconcile YAML with the hosted organization.
|
|
40
59
|
fx dev Start local dev server.
|
|
41
60
|
fx publish Sign current manifest; optionally push to manifest-worker.
|
|
42
61
|
fx report <experimentId> Print results for an experiment.
|
|
43
62
|
fx kill <experimentId> Kill a running experiment. Requires --reason.
|
|
44
63
|
fx import-mojito <dir> Convert Mojito waves and emit a compatibility report.
|
|
64
|
+
fx init databricks-tests Scaffold a TypeScript/Gherkin Databricks suite.
|
|
65
|
+
fx test publish <file> Publish BDD/live/JUnit/CLI evidence to Quality Center.
|
|
66
|
+
fx login Configure and verify a secure hosted profile.
|
|
67
|
+
fx logout [profile] Remove a hosted profile.
|
|
68
|
+
fx profile [list|show|use] Inspect or switch profiles without printing secrets.
|
|
69
|
+
fx doctor Verify API, gateway, tenant, role, and config security.
|
|
45
70
|
```
|
|
46
71
|
|
|
47
72
|
For a migration gate that fails until every trigger and asset is portable:
|
package/dist/bin/fx.cjs
CHANGED
|
@@ -11,6 +11,10 @@ var http = require('http');
|
|
|
11
11
|
var module$1 = require('module');
|
|
12
12
|
var databricksTestkit = require('@fabricorg/databricks-testkit');
|
|
13
13
|
var fastXmlParser = require('fast-xml-parser');
|
|
14
|
+
var child_process = require('child_process');
|
|
15
|
+
var os = require('os');
|
|
16
|
+
var util$1 = require('util');
|
|
17
|
+
var process$1 = require('process');
|
|
14
18
|
|
|
15
19
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
16
20
|
var __defProp = Object.defineProperty;
|
|
@@ -7437,6 +7441,39 @@ var AuditEvent = external_exports.object({
|
|
|
7437
7441
|
payload: external_exports.record(external_exports.unknown())
|
|
7438
7442
|
});
|
|
7439
7443
|
var AuditListResponse = external_exports.object({ events: external_exports.array(AuditEvent) });
|
|
7444
|
+
var GovernanceSettings = external_exports.object({
|
|
7445
|
+
requireQualityForProduction: external_exports.boolean(),
|
|
7446
|
+
requiredQualitySuites: external_exports.array(external_exports.string().min(1).max(240)).max(50),
|
|
7447
|
+
qualityMaxAgeHours: external_exports.number().int().min(1).max(8760),
|
|
7448
|
+
retentionDays: external_exports.number().int().min(30).max(3650),
|
|
7449
|
+
legalHold: external_exports.boolean(),
|
|
7450
|
+
updatedBy: external_exports.string().nullable(),
|
|
7451
|
+
updatedAt: external_exports.string().datetime().nullable()
|
|
7452
|
+
});
|
|
7453
|
+
var UpdateGovernanceSettingsInput = GovernanceSettings.pick({
|
|
7454
|
+
requireQualityForProduction: true,
|
|
7455
|
+
requiredQualitySuites: true,
|
|
7456
|
+
qualityMaxAgeHours: true,
|
|
7457
|
+
retentionDays: true,
|
|
7458
|
+
legalHold: true
|
|
7459
|
+
});
|
|
7460
|
+
var QualityGateResult = external_exports.object({
|
|
7461
|
+
enabled: external_exports.boolean(),
|
|
7462
|
+
passed: external_exports.boolean(),
|
|
7463
|
+
checks: external_exports.array(
|
|
7464
|
+
external_exports.object({
|
|
7465
|
+
suite: external_exports.string(),
|
|
7466
|
+
passed: external_exports.boolean(),
|
|
7467
|
+
reason: external_exports.string(),
|
|
7468
|
+
runId: external_exports.string().nullable(),
|
|
7469
|
+
finishedAt: external_exports.string().datetime().nullable()
|
|
7470
|
+
})
|
|
7471
|
+
)
|
|
7472
|
+
});
|
|
7473
|
+
var GovernanceStatusResponse = external_exports.object({
|
|
7474
|
+
settings: GovernanceSettings,
|
|
7475
|
+
qualityGate: QualityGateResult
|
|
7476
|
+
});
|
|
7440
7477
|
var AuditExport = external_exports.object({
|
|
7441
7478
|
id: external_exports.string(),
|
|
7442
7479
|
destinationKind: external_exports.enum(["s3", "r2", "splunk-hec"]),
|
|
@@ -7758,6 +7795,22 @@ var endpoints = {
|
|
|
7758
7795
|
mutates: false,
|
|
7759
7796
|
requiresRole: "viewer"
|
|
7760
7797
|
},
|
|
7798
|
+
"governance.get": {
|
|
7799
|
+
method: "GET",
|
|
7800
|
+
path: "/v1/orgs/:orgId/governance",
|
|
7801
|
+
params: Empty,
|
|
7802
|
+
response: GovernanceStatusResponse,
|
|
7803
|
+
mutates: false,
|
|
7804
|
+
requiresRole: "viewer"
|
|
7805
|
+
},
|
|
7806
|
+
"governance.update": {
|
|
7807
|
+
method: "POST",
|
|
7808
|
+
path: "/v1/orgs/:orgId/governance",
|
|
7809
|
+
params: UpdateGovernanceSettingsInput,
|
|
7810
|
+
response: GovernanceStatusResponse,
|
|
7811
|
+
mutates: true,
|
|
7812
|
+
requiresRole: "admin"
|
|
7813
|
+
},
|
|
7761
7814
|
"audit.exports.list": {
|
|
7762
7815
|
method: "GET",
|
|
7763
7816
|
path: "/v1/orgs/:orgId/audit/exports",
|
|
@@ -8009,6 +8062,10 @@ var ApiClient = class {
|
|
|
8009
8062
|
audit = {
|
|
8010
8063
|
list: (orgId) => this.call("audit.list", {}, orgId ? { orgId } : void 0)
|
|
8011
8064
|
};
|
|
8065
|
+
governance = {
|
|
8066
|
+
get: (orgId) => this.call("governance.get", {}, orgId ? { orgId } : void 0),
|
|
8067
|
+
update: (params, orgId) => this.call("governance.update", params, orgId ? { orgId } : void 0)
|
|
8068
|
+
};
|
|
8012
8069
|
preview = {
|
|
8013
8070
|
sign: (params, orgId) => this.call("preview.sign", params, orgId ? { orgId } : void 0)
|
|
8014
8071
|
};
|
|
@@ -8056,6 +8113,7 @@ async function cmdPreview(experimentId, options) {
|
|
|
8056
8113
|
const client = new ApiClient({
|
|
8057
8114
|
baseUrl: options.apiUrl,
|
|
8058
8115
|
apiKey: options.apiKey,
|
|
8116
|
+
bearerToken: options.bearerToken,
|
|
8059
8117
|
defaultOrgId: tenantId
|
|
8060
8118
|
});
|
|
8061
8119
|
const r = await client.call(
|
|
@@ -8142,7 +8200,12 @@ async function cmdPush(dir, options = {}) {
|
|
|
8142
8200
|
);
|
|
8143
8201
|
return 1;
|
|
8144
8202
|
}
|
|
8145
|
-
const api = new ApiClient({
|
|
8203
|
+
const api = new ApiClient({
|
|
8204
|
+
baseUrl: apiUrl,
|
|
8205
|
+
apiKey,
|
|
8206
|
+
bearerToken: options.bearerToken,
|
|
8207
|
+
defaultOrgId: tenantId
|
|
8208
|
+
});
|
|
8146
8209
|
const specs = (await loadExperimentDir(path.resolve(dir))).map((s) => s.spec);
|
|
8147
8210
|
const summaries = (await api.experiments.list()).experiments;
|
|
8148
8211
|
const current = [];
|
|
@@ -8527,6 +8590,141 @@ async function writeState(path$1, state) {
|
|
|
8527
8590
|
await promises.writeFile(path$1, `${JSON.stringify(state, null, 2)}
|
|
8528
8591
|
`, "utf8");
|
|
8529
8592
|
}
|
|
8593
|
+
var execFileAsync = util$1.promisify(child_process.execFile);
|
|
8594
|
+
function defaultConfigPath(env = process.env) {
|
|
8595
|
+
const configDir = env.FX_CONFIG_DIR ?? (process.platform === "win32" ? path.join(env.APPDATA ?? os.homedir(), "Fabric Experiments") : path.join(env.XDG_CONFIG_HOME ?? path.join(os.homedir(), ".config"), "fabric-experiments"));
|
|
8596
|
+
return path.join(configDir, "config.json");
|
|
8597
|
+
}
|
|
8598
|
+
async function loadHostedConfig(path = defaultConfigPath()) {
|
|
8599
|
+
try {
|
|
8600
|
+
const parsed = JSON.parse(await promises.readFile(path, "utf8"));
|
|
8601
|
+
return {
|
|
8602
|
+
version: 1,
|
|
8603
|
+
activeProfile: parsed.activeProfile,
|
|
8604
|
+
profiles: parsed.profiles ?? {}
|
|
8605
|
+
};
|
|
8606
|
+
} catch (error) {
|
|
8607
|
+
if (error.code === "ENOENT") {
|
|
8608
|
+
return { version: 1, profiles: {} };
|
|
8609
|
+
}
|
|
8610
|
+
throw new Error(`Unable to read Fabric CLI config at ${path}: ${error.message}`);
|
|
8611
|
+
}
|
|
8612
|
+
}
|
|
8613
|
+
async function saveHostedConfig(config, path$1 = defaultConfigPath()) {
|
|
8614
|
+
await promises.mkdir(path.dirname(path$1), { recursive: true, mode: 448 });
|
|
8615
|
+
const temporary = `${path$1}.${process.pid}.tmp`;
|
|
8616
|
+
await promises.writeFile(temporary, `${JSON.stringify(config, null, 2)}
|
|
8617
|
+
`, { mode: 384 });
|
|
8618
|
+
await promises.rename(temporary, path$1);
|
|
8619
|
+
await promises.chmod(path$1, 384);
|
|
8620
|
+
}
|
|
8621
|
+
async function removeHostedProfile(profileName, path = defaultConfigPath()) {
|
|
8622
|
+
const config = await loadHostedConfig(path);
|
|
8623
|
+
if (!config.profiles[profileName]) return false;
|
|
8624
|
+
delete config.profiles[profileName];
|
|
8625
|
+
if (config.activeProfile === profileName) {
|
|
8626
|
+
config.activeProfile = Object.keys(config.profiles).sort()[0];
|
|
8627
|
+
}
|
|
8628
|
+
if (Object.keys(config.profiles).length === 0) {
|
|
8629
|
+
try {
|
|
8630
|
+
await promises.unlink(path);
|
|
8631
|
+
} catch (error) {
|
|
8632
|
+
if (error.code !== "ENOENT") throw error;
|
|
8633
|
+
}
|
|
8634
|
+
return true;
|
|
8635
|
+
}
|
|
8636
|
+
await saveHostedConfig(config, path);
|
|
8637
|
+
return true;
|
|
8638
|
+
}
|
|
8639
|
+
async function configPermissionsArePrivate(path = defaultConfigPath()) {
|
|
8640
|
+
if (process.platform === "win32") return true;
|
|
8641
|
+
try {
|
|
8642
|
+
const details = await promises.stat(path);
|
|
8643
|
+
return (details.mode & 63) === 0;
|
|
8644
|
+
} catch (error) {
|
|
8645
|
+
if (error.code === "ENOENT") return true;
|
|
8646
|
+
throw error;
|
|
8647
|
+
}
|
|
8648
|
+
}
|
|
8649
|
+
async function resolveHostedContext(options = {}) {
|
|
8650
|
+
const env = options.env ?? process.env;
|
|
8651
|
+
const config = await loadHostedConfig(options.configPath ?? defaultConfigPath(env));
|
|
8652
|
+
const profileName = options.profileName ?? env.FX_PROFILE ?? config.activeProfile;
|
|
8653
|
+
const profile = profileName ? config.profiles[profileName] : void 0;
|
|
8654
|
+
const apiUrl = options.apiUrl ?? env.FX_API_URL ?? profile?.apiUrl;
|
|
8655
|
+
const apiKey = options.apiKey ?? env.FX_API_KEY ?? profile?.apiKey;
|
|
8656
|
+
const tenantId = options.tenantId ?? env.FX_ORG_ID ?? profile?.orgId;
|
|
8657
|
+
const bearerToken = options.bearerToken ?? (apiUrl ? await resolveGatewayBearer(apiUrl, {
|
|
8658
|
+
env,
|
|
8659
|
+
databricksProfile: profile?.databricksProfile,
|
|
8660
|
+
tokenProvider: options.tokenProvider
|
|
8661
|
+
}) : void 0);
|
|
8662
|
+
return { profileName, apiUrl, apiKey, tenantId, bearerToken };
|
|
8663
|
+
}
|
|
8664
|
+
async function resolveStudioApiUrl(studioUrl, fetchImpl = globalThis.fetch) {
|
|
8665
|
+
const source = new URL(studioUrl);
|
|
8666
|
+
const response = await fetchImpl(source.toString(), { method: "HEAD", redirect: "manual" });
|
|
8667
|
+
const location = response.headers.get("location");
|
|
8668
|
+
const target = location ? new URL(location, source) : source;
|
|
8669
|
+
target.pathname = "/api";
|
|
8670
|
+
target.search = "";
|
|
8671
|
+
target.hash = "";
|
|
8672
|
+
return target.toString().replace(/\/$/, "");
|
|
8673
|
+
}
|
|
8674
|
+
async function resolveGatewayBearer(apiUrl, options = {}) {
|
|
8675
|
+
const env = options.env ?? process.env;
|
|
8676
|
+
if (env.FX_GATEWAY_BEARER_TOKEN) return env.FX_GATEWAY_BEARER_TOKEN;
|
|
8677
|
+
if (!new URL(apiUrl).hostname.endsWith(".databricksapps.com")) return void 0;
|
|
8678
|
+
const databricksProfile = options.databricksProfile ?? env.FX_DATABRICKS_PROFILE;
|
|
8679
|
+
if (databricksProfile) {
|
|
8680
|
+
return (options.tokenProvider ?? databricksCliToken)(databricksProfile);
|
|
8681
|
+
}
|
|
8682
|
+
const host = env.DATABRICKS_HOST?.replace(/\/$/, "");
|
|
8683
|
+
const clientId = env.FX_QUALITY_DATABRICKS_CLIENT_ID ?? env.DATABRICKS_CLIENT_ID;
|
|
8684
|
+
const clientSecret = env.FX_QUALITY_DATABRICKS_CLIENT_SECRET ?? env.DATABRICKS_CLIENT_SECRET;
|
|
8685
|
+
if (!host || !clientId || !clientSecret) {
|
|
8686
|
+
try {
|
|
8687
|
+
return await (options.tokenProvider ?? databricksCliToken)();
|
|
8688
|
+
} catch {
|
|
8689
|
+
throw new Error(
|
|
8690
|
+
"Databricks Apps access requires a Databricks CLI login, --databricks-profile, FX_DATABRICKS_PROFILE, or DATABRICKS_HOST with client credentials"
|
|
8691
|
+
);
|
|
8692
|
+
}
|
|
8693
|
+
}
|
|
8694
|
+
const response = await fetch(`${host}/oidc/v1/token`, {
|
|
8695
|
+
method: "POST",
|
|
8696
|
+
headers: {
|
|
8697
|
+
authorization: `Basic ${Buffer.from(`${clientId}:${clientSecret}`).toString("base64")}`,
|
|
8698
|
+
"content-type": "application/x-www-form-urlencoded"
|
|
8699
|
+
},
|
|
8700
|
+
body: new URLSearchParams({ grant_type: "client_credentials", scope: "all-apis" })
|
|
8701
|
+
});
|
|
8702
|
+
if (!response.ok) {
|
|
8703
|
+
throw new Error(`Databricks OAuth failed (${response.status} ${response.statusText})`);
|
|
8704
|
+
}
|
|
8705
|
+
const body = await response.json();
|
|
8706
|
+
if (typeof body.access_token !== "string" || !body.access_token) {
|
|
8707
|
+
throw new Error("Databricks OAuth response did not include an access token");
|
|
8708
|
+
}
|
|
8709
|
+
return body.access_token;
|
|
8710
|
+
}
|
|
8711
|
+
async function databricksCliToken(profile) {
|
|
8712
|
+
try {
|
|
8713
|
+
const args = ["auth", "token", ...profile ? [profile] : [], "--output", "json"];
|
|
8714
|
+
const { stdout } = await execFileAsync("databricks", args, { encoding: "utf8" });
|
|
8715
|
+
const parsed = JSON.parse(stdout);
|
|
8716
|
+
if (typeof parsed.access_token !== "string" || !parsed.access_token) {
|
|
8717
|
+
throw new Error("token response did not include access_token");
|
|
8718
|
+
}
|
|
8719
|
+
return parsed.access_token;
|
|
8720
|
+
} catch (error) {
|
|
8721
|
+
throw new Error(
|
|
8722
|
+
`Unable to obtain a Databricks token${profile ? ` for profile ${profile}` : ""}: ${error.message}`
|
|
8723
|
+
);
|
|
8724
|
+
}
|
|
8725
|
+
}
|
|
8726
|
+
|
|
8727
|
+
// src/commands/test-publish.ts
|
|
8530
8728
|
async function cmdTestPublish(evidencePath, options = {}) {
|
|
8531
8729
|
const env = options.env ?? process.env;
|
|
8532
8730
|
const apiUrl = options.apiUrl ?? env.FX_API_URL;
|
|
@@ -8555,30 +8753,7 @@ async function cmdTestPublish(evidencePath, options = {}) {
|
|
|
8555
8753
|
return 0;
|
|
8556
8754
|
}
|
|
8557
8755
|
async function resolveGatewayToken(apiUrl, env) {
|
|
8558
|
-
|
|
8559
|
-
if (!new URL(apiUrl).hostname.endsWith(".databricksapps.com")) return void 0;
|
|
8560
|
-
const host = env.DATABRICKS_HOST?.replace(/\/$/, "");
|
|
8561
|
-
const clientId = env.FX_QUALITY_DATABRICKS_CLIENT_ID ?? env.DATABRICKS_CLIENT_ID;
|
|
8562
|
-
const clientSecret = env.FX_QUALITY_DATABRICKS_CLIENT_SECRET ?? env.DATABRICKS_CLIENT_SECRET;
|
|
8563
|
-
if (!host || !clientId || !clientSecret) {
|
|
8564
|
-
throw new Error("Databricks Apps publication requires DATABRICKS_HOST and client credentials");
|
|
8565
|
-
}
|
|
8566
|
-
const response = await fetch(`${host}/oidc/v1/token`, {
|
|
8567
|
-
method: "POST",
|
|
8568
|
-
headers: {
|
|
8569
|
-
authorization: `Basic ${Buffer.from(`${clientId}:${clientSecret}`).toString("base64")}`,
|
|
8570
|
-
"content-type": "application/x-www-form-urlencoded"
|
|
8571
|
-
},
|
|
8572
|
-
body: new URLSearchParams({ grant_type: "client_credentials", scope: "all-apis" })
|
|
8573
|
-
});
|
|
8574
|
-
if (!response.ok) {
|
|
8575
|
-
throw new Error(`Databricks OAuth failed (${response.status} ${response.statusText})`);
|
|
8576
|
-
}
|
|
8577
|
-
const body = await response.json();
|
|
8578
|
-
if (typeof body.access_token !== "string" || !body.access_token) {
|
|
8579
|
-
throw new Error("Databricks OAuth response did not include an access token");
|
|
8580
|
-
}
|
|
8581
|
-
return body.access_token;
|
|
8756
|
+
return resolveGatewayBearer(apiUrl, { env });
|
|
8582
8757
|
}
|
|
8583
8758
|
function normalizeTestEvidence(value, options = {}) {
|
|
8584
8759
|
if (!value || typeof value !== "object") throw new Error("Evidence must be a JSON object");
|
|
@@ -8812,6 +8987,188 @@ function isoOrNull(value) {
|
|
|
8812
8987
|
if (typeof value !== "string" || Number.isNaN(Date.parse(value))) return null;
|
|
8813
8988
|
return new Date(value).toISOString();
|
|
8814
8989
|
}
|
|
8990
|
+
async function cmdLogin(options = {}) {
|
|
8991
|
+
const env = options.env ?? process.env;
|
|
8992
|
+
const profileName = options.profileName ?? "production";
|
|
8993
|
+
const apiUrl = options.apiUrl ? normalizeApiUrl(options.apiUrl) : await resolveStudioApiUrl(
|
|
8994
|
+
options.studioUrl ?? "https://studio.experiments.fabric.pro",
|
|
8995
|
+
options.fetchImpl
|
|
8996
|
+
);
|
|
8997
|
+
const apiKey = options.apiKey ?? env.FX_API_KEY ?? await (options.promptSecret ?? readSecretApiKey)();
|
|
8998
|
+
if (!apiKey) throw new Error("A Fabric API key is required");
|
|
8999
|
+
const bearerToken = await resolveGatewayBearer(apiUrl, {
|
|
9000
|
+
env,
|
|
9001
|
+
databricksProfile: options.databricksProfile,
|
|
9002
|
+
tokenProvider: options.tokenProvider
|
|
9003
|
+
});
|
|
9004
|
+
const client = new ApiClient({
|
|
9005
|
+
baseUrl: apiUrl,
|
|
9006
|
+
apiKey,
|
|
9007
|
+
bearerToken,
|
|
9008
|
+
fetchImpl: options.fetchImpl
|
|
9009
|
+
});
|
|
9010
|
+
const tenant = await client.tenants.me();
|
|
9011
|
+
if (options.tenantId && options.tenantId !== tenant.organization.id) {
|
|
9012
|
+
throw new Error(
|
|
9013
|
+
`API key belongs to ${tenant.organization.id}, not requested organization ${options.tenantId}`
|
|
9014
|
+
);
|
|
9015
|
+
}
|
|
9016
|
+
const now3 = (/* @__PURE__ */ new Date()).toISOString();
|
|
9017
|
+
const path = options.configPath ?? defaultConfigPath(env);
|
|
9018
|
+
const config = await loadHostedConfig(path);
|
|
9019
|
+
const existing = config.profiles[profileName];
|
|
9020
|
+
config.profiles[profileName] = {
|
|
9021
|
+
apiUrl,
|
|
9022
|
+
apiKey,
|
|
9023
|
+
orgId: tenant.organization.id,
|
|
9024
|
+
organizationName: tenant.organization.name,
|
|
9025
|
+
organizationSlug: tenant.organization.slug,
|
|
9026
|
+
role: tenant.member.role,
|
|
9027
|
+
databricksProfile: options.databricksProfile,
|
|
9028
|
+
createdAt: existing?.createdAt ?? now3,
|
|
9029
|
+
updatedAt: now3
|
|
9030
|
+
};
|
|
9031
|
+
config.activeProfile = profileName;
|
|
9032
|
+
await saveHostedConfig(config, path);
|
|
9033
|
+
process.stdout.write(
|
|
9034
|
+
`Logged in to ${tenant.organization.name} as ${tenant.member.role} (profile: ${profileName}).
|
|
9035
|
+
`
|
|
9036
|
+
);
|
|
9037
|
+
return 0;
|
|
9038
|
+
}
|
|
9039
|
+
async function cmdLogout(profileName, options = {}) {
|
|
9040
|
+
const env = options.env ?? process.env;
|
|
9041
|
+
const path = options.configPath ?? defaultConfigPath(env);
|
|
9042
|
+
const config = await loadHostedConfig(path);
|
|
9043
|
+
const target = profileName ?? config.activeProfile;
|
|
9044
|
+
if (!target) {
|
|
9045
|
+
process.stdout.write("No Fabric CLI profile is configured.\n");
|
|
9046
|
+
return 0;
|
|
9047
|
+
}
|
|
9048
|
+
const removed = await removeHostedProfile(target, path);
|
|
9049
|
+
process.stdout.write(
|
|
9050
|
+
removed ? `Logged out profile ${target}.
|
|
9051
|
+
` : `Profile ${target} not found.
|
|
9052
|
+
`
|
|
9053
|
+
);
|
|
9054
|
+
return removed ? 0 : 1;
|
|
9055
|
+
}
|
|
9056
|
+
async function cmdProfile(action = "list", profileName, options = {}) {
|
|
9057
|
+
const env = options.env ?? process.env;
|
|
9058
|
+
const path = options.configPath ?? defaultConfigPath(env);
|
|
9059
|
+
const config = await loadHostedConfig(path);
|
|
9060
|
+
if (action === "use") {
|
|
9061
|
+
if (!profileName || !config.profiles[profileName]) {
|
|
9062
|
+
process.stderr.write("Usage: fx profile use <name>\n");
|
|
9063
|
+
return 1;
|
|
9064
|
+
}
|
|
9065
|
+
config.activeProfile = profileName;
|
|
9066
|
+
await saveHostedConfig(config, path);
|
|
9067
|
+
process.stdout.write(`Active profile: ${profileName}
|
|
9068
|
+
`);
|
|
9069
|
+
return 0;
|
|
9070
|
+
}
|
|
9071
|
+
if (action === "show") {
|
|
9072
|
+
const selected = profileName ?? config.activeProfile;
|
|
9073
|
+
const profile = selected ? config.profiles[selected] : void 0;
|
|
9074
|
+
if (!selected || !profile) {
|
|
9075
|
+
process.stderr.write("No active Fabric CLI profile. Run fx login.\n");
|
|
9076
|
+
return 1;
|
|
9077
|
+
}
|
|
9078
|
+
process.stdout.write(formatProfile(selected, profile, selected === config.activeProfile));
|
|
9079
|
+
return 0;
|
|
9080
|
+
}
|
|
9081
|
+
const names = Object.keys(config.profiles).sort();
|
|
9082
|
+
if (names.length === 0) {
|
|
9083
|
+
process.stdout.write("No Fabric CLI profiles. Run fx login.\n");
|
|
9084
|
+
return 0;
|
|
9085
|
+
}
|
|
9086
|
+
for (const name of names) {
|
|
9087
|
+
process.stdout.write(
|
|
9088
|
+
formatProfile(name, config.profiles[name], name === config.activeProfile)
|
|
9089
|
+
);
|
|
9090
|
+
}
|
|
9091
|
+
return 0;
|
|
9092
|
+
}
|
|
9093
|
+
async function cmdDoctor(options = {}) {
|
|
9094
|
+
const env = options.env ?? process.env;
|
|
9095
|
+
const path = options.configPath ?? defaultConfigPath(env);
|
|
9096
|
+
const context = await resolveHostedContext({
|
|
9097
|
+
profileName: options.profileName,
|
|
9098
|
+
env,
|
|
9099
|
+
configPath: path,
|
|
9100
|
+
tokenProvider: options.tokenProvider
|
|
9101
|
+
});
|
|
9102
|
+
if (!context.apiUrl || !context.apiKey || !context.tenantId) {
|
|
9103
|
+
process.stderr.write("No complete hosted profile. Run fx login.\n");
|
|
9104
|
+
return 1;
|
|
9105
|
+
}
|
|
9106
|
+
const client = new ApiClient({
|
|
9107
|
+
baseUrl: context.apiUrl,
|
|
9108
|
+
apiKey: context.apiKey,
|
|
9109
|
+
bearerToken: context.bearerToken,
|
|
9110
|
+
defaultOrgId: context.tenantId,
|
|
9111
|
+
fetchImpl: options.fetchImpl
|
|
9112
|
+
});
|
|
9113
|
+
const tenant = await client.tenants.me();
|
|
9114
|
+
const privatePermissions = await configPermissionsArePrivate(path);
|
|
9115
|
+
process.stdout.write(
|
|
9116
|
+
[
|
|
9117
|
+
"Fabric CLI doctor",
|
|
9118
|
+
` Profile: ${context.profileName ?? "(environment)"}`,
|
|
9119
|
+
` API: ${context.apiUrl}`,
|
|
9120
|
+
` Organization: ${tenant.organization.name} (${tenant.organization.id})`,
|
|
9121
|
+
` Role: ${tenant.member.role}`,
|
|
9122
|
+
` Gateway: ${context.bearerToken ? "authenticated" : "not required"}`,
|
|
9123
|
+
` Config mode: ${privatePermissions ? "private" : "INSECURE"}`,
|
|
9124
|
+
""
|
|
9125
|
+
].join("\n")
|
|
9126
|
+
);
|
|
9127
|
+
return privatePermissions ? 0 : 2;
|
|
9128
|
+
}
|
|
9129
|
+
function normalizeApiUrl(value) {
|
|
9130
|
+
const url = new URL(value);
|
|
9131
|
+
if (!url.pathname || url.pathname === "/") url.pathname = "/api";
|
|
9132
|
+
return url.toString().replace(/\/$/, "");
|
|
9133
|
+
}
|
|
9134
|
+
function formatProfile(name, profile, active) {
|
|
9135
|
+
return `${active ? "*" : " "} ${name} \u2014 ${profile.organizationName ?? profile.orgId} (${profile.role ?? "unknown"})
|
|
9136
|
+
${profile.apiUrl}
|
|
9137
|
+
`;
|
|
9138
|
+
}
|
|
9139
|
+
async function readSecretApiKey() {
|
|
9140
|
+
if (!process$1.stdin.isTTY || typeof process$1.stdin.setRawMode !== "function") {
|
|
9141
|
+
throw new Error("Set FX_API_KEY or pass --api-key when stdin is not interactive");
|
|
9142
|
+
}
|
|
9143
|
+
process$1.stderr.write("Fabric API key: ");
|
|
9144
|
+
process$1.stdin.setRawMode(true);
|
|
9145
|
+
process$1.stdin.resume();
|
|
9146
|
+
return new Promise((resolve11, reject) => {
|
|
9147
|
+
let value = "";
|
|
9148
|
+
const onData = (chunk) => {
|
|
9149
|
+
const text = chunk.toString("utf8");
|
|
9150
|
+
if (text === "") {
|
|
9151
|
+
cleanup();
|
|
9152
|
+
reject(new Error("Login canceled"));
|
|
9153
|
+
return;
|
|
9154
|
+
}
|
|
9155
|
+
if (text === "\r" || text === "\n") {
|
|
9156
|
+
cleanup();
|
|
9157
|
+
process$1.stderr.write("\n");
|
|
9158
|
+
resolve11(value.trim());
|
|
9159
|
+
return;
|
|
9160
|
+
}
|
|
9161
|
+
if (text === "\x7F") value = value.slice(0, -1);
|
|
9162
|
+
else value += text;
|
|
9163
|
+
};
|
|
9164
|
+
const cleanup = () => {
|
|
9165
|
+
process$1.stdin.off("data", onData);
|
|
9166
|
+
process$1.stdin.setRawMode(false);
|
|
9167
|
+
process$1.stdin.pause();
|
|
9168
|
+
};
|
|
9169
|
+
process$1.stdin.on("data", onData);
|
|
9170
|
+
});
|
|
9171
|
+
}
|
|
8815
9172
|
|
|
8816
9173
|
// src/bin/fx.ts
|
|
8817
9174
|
var HELP = `fx \u2014 Fabric Experiments CLI
|
|
@@ -8833,6 +9190,10 @@ COMMANDS
|
|
|
8833
9190
|
test env <action> Create, destroy, list, or reap Databricks test environments.
|
|
8834
9191
|
test publish <file> Publish BDD/live/JUnit/CLI evidence to Studio Quality.
|
|
8835
9192
|
init databricks-tests Scaffold a Databricks BDD test project.
|
|
9193
|
+
login Configure and verify a secure hosted profile.
|
|
9194
|
+
logout [profile] Remove a stored hosted profile.
|
|
9195
|
+
profile [list|show|use] Inspect or switch hosted profiles.
|
|
9196
|
+
doctor Verify API, tenant, gateway, role, and config security.
|
|
8836
9197
|
|
|
8837
9198
|
GLOBAL FLAGS
|
|
8838
9199
|
--tenant <id> Tenant scope (default: default)
|
|
@@ -8849,6 +9210,9 @@ GLOBAL FLAGS
|
|
|
8849
9210
|
--static <dir> publish: write signed manifest + tag-loader bundle to <dir>
|
|
8850
9211
|
--api-url <url> push/preview/test publish: hosted API base URL
|
|
8851
9212
|
--api-key <key> push/preview/test publish: hosted API key
|
|
9213
|
+
--profile <name> hosted profile (default: active profile)
|
|
9214
|
+
--studio-url <url> login: branded Studio URL
|
|
9215
|
+
--databricks-profile <p> login: Databricks CLI profile used for Apps OAuth
|
|
8852
9216
|
--no-publish push: apply actions without publishing manifest
|
|
8853
9217
|
--name <name> test env: environment name (for example pr-1234)
|
|
8854
9218
|
--seed <dir> test env create: JSON fixture directory
|
|
@@ -8867,7 +9231,7 @@ GLOBAL FLAGS
|
|
|
8867
9231
|
-h, --help print this help
|
|
8868
9232
|
-v, --version print version
|
|
8869
9233
|
`;
|
|
8870
|
-
var VERSION2 = "0.
|
|
9234
|
+
var VERSION2 = "0.7.0";
|
|
8871
9235
|
function parse2(argv) {
|
|
8872
9236
|
const positional = [];
|
|
8873
9237
|
const flags = {};
|
|
@@ -8912,13 +9276,32 @@ async function main() {
|
|
|
8912
9276
|
`);
|
|
8913
9277
|
return 0;
|
|
8914
9278
|
}
|
|
8915
|
-
const
|
|
9279
|
+
const explicitTenantId = args.flags.tenant;
|
|
9280
|
+
const tenantId = explicitTenantId ?? "default";
|
|
8916
9281
|
const allowDeletes = args.flags["allow-deletes"] === true;
|
|
8917
9282
|
switch (args.command) {
|
|
8918
9283
|
case "":
|
|
8919
9284
|
case "help":
|
|
8920
9285
|
process.stdout.write(HELP);
|
|
8921
9286
|
return 0;
|
|
9287
|
+
case "login":
|
|
9288
|
+
return cmdLogin({
|
|
9289
|
+
profileName: args.flags.profile,
|
|
9290
|
+
studioUrl: args.flags["studio-url"],
|
|
9291
|
+
apiUrl: args.flags["api-url"],
|
|
9292
|
+
apiKey: args.flags["api-key"],
|
|
9293
|
+
tenantId: explicitTenantId,
|
|
9294
|
+
databricksProfile: args.flags["databricks-profile"]
|
|
9295
|
+
});
|
|
9296
|
+
case "logout":
|
|
9297
|
+
return cmdLogout(args.positional[0] ?? args.flags.profile);
|
|
9298
|
+
case "profile":
|
|
9299
|
+
return cmdProfile(
|
|
9300
|
+
args.positional[0] ?? "list",
|
|
9301
|
+
args.positional[1] ?? args.flags.profile
|
|
9302
|
+
);
|
|
9303
|
+
case "doctor":
|
|
9304
|
+
return cmdDoctor({ profileName: args.flags.profile });
|
|
8922
9305
|
case "validate":
|
|
8923
9306
|
return cmdValidate(args.positional[0] ?? ".");
|
|
8924
9307
|
case "plan":
|
|
@@ -8937,17 +9320,25 @@ async function main() {
|
|
|
8937
9320
|
dryRun: args.flags["dry-run"] === true,
|
|
8938
9321
|
allowDeletes
|
|
8939
9322
|
});
|
|
8940
|
-
case "push":
|
|
9323
|
+
case "push": {
|
|
9324
|
+
const hosted = await resolveHostedContext({
|
|
9325
|
+
profileName: args.flags.profile,
|
|
9326
|
+
apiUrl: args.flags["api-url"],
|
|
9327
|
+
apiKey: args.flags["api-key"],
|
|
9328
|
+
tenantId: explicitTenantId
|
|
9329
|
+
});
|
|
8941
9330
|
return cmdPush(args.positional[0] ?? ".", {
|
|
8942
|
-
tenantId,
|
|
9331
|
+
tenantId: hosted.tenantId,
|
|
8943
9332
|
ownerId: args.flags.owner,
|
|
8944
9333
|
approverId: args.flags.approver,
|
|
8945
9334
|
dryRun: args.flags["dry-run"] === true,
|
|
8946
9335
|
allowDeletes,
|
|
8947
|
-
apiUrl:
|
|
8948
|
-
apiKey:
|
|
9336
|
+
apiUrl: hosted.apiUrl,
|
|
9337
|
+
apiKey: hosted.apiKey,
|
|
9338
|
+
bearerToken: hosted.bearerToken,
|
|
8949
9339
|
publish: args.flags["no-publish"] !== true
|
|
8950
9340
|
});
|
|
9341
|
+
}
|
|
8951
9342
|
case "dev":
|
|
8952
9343
|
return cmdDev({
|
|
8953
9344
|
port: args.flags.port ? Number(args.flags.port) : void 0,
|
|
@@ -8990,32 +9381,47 @@ async function main() {
|
|
|
8990
9381
|
outputDir: args.flags.out,
|
|
8991
9382
|
reportFile: args.flags.report,
|
|
8992
9383
|
strict: args.flags.strict === true});
|
|
8993
|
-
case "preview":
|
|
9384
|
+
case "preview": {
|
|
8994
9385
|
if (!args.positional[0]) {
|
|
8995
9386
|
process.stderr.write(
|
|
8996
9387
|
"Usage: fx preview <experimentId> --variant <key> [--ttl 900] [--origin https://...] [--api-url ... --api-key ...]\n"
|
|
8997
9388
|
);
|
|
8998
9389
|
return 1;
|
|
8999
9390
|
}
|
|
9391
|
+
const hosted = args.flags.local === true ? {} : await resolveHostedContext({
|
|
9392
|
+
profileName: args.flags.profile,
|
|
9393
|
+
apiUrl: args.flags["api-url"],
|
|
9394
|
+
apiKey: args.flags["api-key"],
|
|
9395
|
+
tenantId: explicitTenantId
|
|
9396
|
+
});
|
|
9000
9397
|
return cmdPreview(args.positional[0], {
|
|
9001
|
-
tenantId,
|
|
9398
|
+
tenantId: hosted.tenantId ?? tenantId,
|
|
9002
9399
|
variantKey: typeof args.flags.variant === "string" ? args.flags.variant : "",
|
|
9003
9400
|
ttlSeconds: args.flags.ttl ? Number(args.flags.ttl) : void 0,
|
|
9004
9401
|
origin: args.flags.origin,
|
|
9005
|
-
apiUrl:
|
|
9006
|
-
apiKey:
|
|
9402
|
+
apiUrl: hosted.apiUrl,
|
|
9403
|
+
apiKey: hosted.apiKey,
|
|
9404
|
+
bearerToken: hosted.bearerToken,
|
|
9007
9405
|
local: args.flags.local === true
|
|
9008
9406
|
});
|
|
9407
|
+
}
|
|
9009
9408
|
case "test":
|
|
9010
9409
|
if (args.positional[0] === "publish") {
|
|
9011
9410
|
if (!args.positional[1]) {
|
|
9012
9411
|
process.stderr.write("Usage: fx test publish <evidence.json|junit.xml> [flags]\n");
|
|
9013
9412
|
return 1;
|
|
9014
9413
|
}
|
|
9015
|
-
|
|
9016
|
-
|
|
9414
|
+
const hosted = await resolveHostedContext({
|
|
9415
|
+
profileName: args.flags.profile,
|
|
9017
9416
|
apiUrl: args.flags["api-url"],
|
|
9018
9417
|
apiKey: args.flags["api-key"],
|
|
9418
|
+
tenantId: explicitTenantId
|
|
9419
|
+
});
|
|
9420
|
+
return cmdTestPublish(args.positional[1], {
|
|
9421
|
+
tenantId: hosted.tenantId,
|
|
9422
|
+
apiUrl: hosted.apiUrl,
|
|
9423
|
+
apiKey: hosted.apiKey,
|
|
9424
|
+
bearerToken: hosted.bearerToken,
|
|
9019
9425
|
suite: args.flags.suite,
|
|
9020
9426
|
externalId: args.flags["external-id"],
|
|
9021
9427
|
runUrl: args.flags["run-url"]
|