@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/dist/bin/fx.js CHANGED
@@ -2,13 +2,17 @@
2
2
  import { realpathSync, existsSync, readFileSync, writeFileSync, mkdirSync } from 'fs';
3
3
  import { resolve, join, basename, dirname, extname } from 'path';
4
4
  import { fileURLToPath } from 'url';
5
- import { mkdir, writeFile, readFile, copyFile, access, readdir, stat } from 'fs/promises';
5
+ import { mkdir, writeFile, readFile, copyFile, access, readdir, stat, rename, chmod, unlink } from 'fs/promises';
6
6
  import { parse, stringify } from 'yaml';
7
7
  import { randomUUID, webcrypto, createHash } from 'crypto';
8
8
  import { createServer } from 'http';
9
9
  import { createRequire } from 'module';
10
10
  import { createWorkspaceContext, deleteEphemeralLakebaseBranch, createEphemeralLakebaseBranch, toLakebaseBranchId } from '@fabricorg/databricks-testkit';
11
11
  import { XMLParser } from 'fast-xml-parser';
12
+ import { execFile } from 'child_process';
13
+ import { homedir } from 'os';
14
+ import { promisify } from 'util';
15
+ import { stdin, stderr } from 'process';
12
16
 
13
17
  var __defProp = Object.defineProperty;
14
18
  var __export = (target, all) => {
@@ -7434,6 +7438,39 @@ var AuditEvent = external_exports.object({
7434
7438
  payload: external_exports.record(external_exports.unknown())
7435
7439
  });
7436
7440
  var AuditListResponse = external_exports.object({ events: external_exports.array(AuditEvent) });
7441
+ var GovernanceSettings = external_exports.object({
7442
+ requireQualityForProduction: external_exports.boolean(),
7443
+ requiredQualitySuites: external_exports.array(external_exports.string().min(1).max(240)).max(50),
7444
+ qualityMaxAgeHours: external_exports.number().int().min(1).max(8760),
7445
+ retentionDays: external_exports.number().int().min(30).max(3650),
7446
+ legalHold: external_exports.boolean(),
7447
+ updatedBy: external_exports.string().nullable(),
7448
+ updatedAt: external_exports.string().datetime().nullable()
7449
+ });
7450
+ var UpdateGovernanceSettingsInput = GovernanceSettings.pick({
7451
+ requireQualityForProduction: true,
7452
+ requiredQualitySuites: true,
7453
+ qualityMaxAgeHours: true,
7454
+ retentionDays: true,
7455
+ legalHold: true
7456
+ });
7457
+ var QualityGateResult = external_exports.object({
7458
+ enabled: external_exports.boolean(),
7459
+ passed: external_exports.boolean(),
7460
+ checks: external_exports.array(
7461
+ external_exports.object({
7462
+ suite: external_exports.string(),
7463
+ passed: external_exports.boolean(),
7464
+ reason: external_exports.string(),
7465
+ runId: external_exports.string().nullable(),
7466
+ finishedAt: external_exports.string().datetime().nullable()
7467
+ })
7468
+ )
7469
+ });
7470
+ var GovernanceStatusResponse = external_exports.object({
7471
+ settings: GovernanceSettings,
7472
+ qualityGate: QualityGateResult
7473
+ });
7437
7474
  var AuditExport = external_exports.object({
7438
7475
  id: external_exports.string(),
7439
7476
  destinationKind: external_exports.enum(["s3", "r2", "splunk-hec"]),
@@ -7755,6 +7792,22 @@ var endpoints = {
7755
7792
  mutates: false,
7756
7793
  requiresRole: "viewer"
7757
7794
  },
7795
+ "governance.get": {
7796
+ method: "GET",
7797
+ path: "/v1/orgs/:orgId/governance",
7798
+ params: Empty,
7799
+ response: GovernanceStatusResponse,
7800
+ mutates: false,
7801
+ requiresRole: "viewer"
7802
+ },
7803
+ "governance.update": {
7804
+ method: "POST",
7805
+ path: "/v1/orgs/:orgId/governance",
7806
+ params: UpdateGovernanceSettingsInput,
7807
+ response: GovernanceStatusResponse,
7808
+ mutates: true,
7809
+ requiresRole: "admin"
7810
+ },
7758
7811
  "audit.exports.list": {
7759
7812
  method: "GET",
7760
7813
  path: "/v1/orgs/:orgId/audit/exports",
@@ -8006,6 +8059,10 @@ var ApiClient = class {
8006
8059
  audit = {
8007
8060
  list: (orgId) => this.call("audit.list", {}, orgId ? { orgId } : void 0)
8008
8061
  };
8062
+ governance = {
8063
+ get: (orgId) => this.call("governance.get", {}, orgId ? { orgId } : void 0),
8064
+ update: (params, orgId) => this.call("governance.update", params, orgId ? { orgId } : void 0)
8065
+ };
8009
8066
  preview = {
8010
8067
  sign: (params, orgId) => this.call("preview.sign", params, orgId ? { orgId } : void 0)
8011
8068
  };
@@ -8053,6 +8110,7 @@ async function cmdPreview(experimentId, options) {
8053
8110
  const client = new ApiClient({
8054
8111
  baseUrl: options.apiUrl,
8055
8112
  apiKey: options.apiKey,
8113
+ bearerToken: options.bearerToken,
8056
8114
  defaultOrgId: tenantId
8057
8115
  });
8058
8116
  const r = await client.call(
@@ -8139,7 +8197,12 @@ async function cmdPush(dir, options = {}) {
8139
8197
  );
8140
8198
  return 1;
8141
8199
  }
8142
- const api = new ApiClient({ baseUrl: apiUrl, apiKey, defaultOrgId: tenantId });
8200
+ const api = new ApiClient({
8201
+ baseUrl: apiUrl,
8202
+ apiKey,
8203
+ bearerToken: options.bearerToken,
8204
+ defaultOrgId: tenantId
8205
+ });
8143
8206
  const specs = (await loadExperimentDir(resolve(dir))).map((s) => s.spec);
8144
8207
  const summaries = (await api.experiments.list()).experiments;
8145
8208
  const current = [];
@@ -8524,6 +8587,141 @@ async function writeState(path, state) {
8524
8587
  await writeFile(path, `${JSON.stringify(state, null, 2)}
8525
8588
  `, "utf8");
8526
8589
  }
8590
+ var execFileAsync = promisify(execFile);
8591
+ function defaultConfigPath(env = process.env) {
8592
+ const configDir = env.FX_CONFIG_DIR ?? (process.platform === "win32" ? join(env.APPDATA ?? homedir(), "Fabric Experiments") : join(env.XDG_CONFIG_HOME ?? join(homedir(), ".config"), "fabric-experiments"));
8593
+ return join(configDir, "config.json");
8594
+ }
8595
+ async function loadHostedConfig(path = defaultConfigPath()) {
8596
+ try {
8597
+ const parsed = JSON.parse(await readFile(path, "utf8"));
8598
+ return {
8599
+ version: 1,
8600
+ activeProfile: parsed.activeProfile,
8601
+ profiles: parsed.profiles ?? {}
8602
+ };
8603
+ } catch (error) {
8604
+ if (error.code === "ENOENT") {
8605
+ return { version: 1, profiles: {} };
8606
+ }
8607
+ throw new Error(`Unable to read Fabric CLI config at ${path}: ${error.message}`);
8608
+ }
8609
+ }
8610
+ async function saveHostedConfig(config, path = defaultConfigPath()) {
8611
+ await mkdir(dirname(path), { recursive: true, mode: 448 });
8612
+ const temporary = `${path}.${process.pid}.tmp`;
8613
+ await writeFile(temporary, `${JSON.stringify(config, null, 2)}
8614
+ `, { mode: 384 });
8615
+ await rename(temporary, path);
8616
+ await chmod(path, 384);
8617
+ }
8618
+ async function removeHostedProfile(profileName, path = defaultConfigPath()) {
8619
+ const config = await loadHostedConfig(path);
8620
+ if (!config.profiles[profileName]) return false;
8621
+ delete config.profiles[profileName];
8622
+ if (config.activeProfile === profileName) {
8623
+ config.activeProfile = Object.keys(config.profiles).sort()[0];
8624
+ }
8625
+ if (Object.keys(config.profiles).length === 0) {
8626
+ try {
8627
+ await unlink(path);
8628
+ } catch (error) {
8629
+ if (error.code !== "ENOENT") throw error;
8630
+ }
8631
+ return true;
8632
+ }
8633
+ await saveHostedConfig(config, path);
8634
+ return true;
8635
+ }
8636
+ async function configPermissionsArePrivate(path = defaultConfigPath()) {
8637
+ if (process.platform === "win32") return true;
8638
+ try {
8639
+ const details = await stat(path);
8640
+ return (details.mode & 63) === 0;
8641
+ } catch (error) {
8642
+ if (error.code === "ENOENT") return true;
8643
+ throw error;
8644
+ }
8645
+ }
8646
+ async function resolveHostedContext(options = {}) {
8647
+ const env = options.env ?? process.env;
8648
+ const config = await loadHostedConfig(options.configPath ?? defaultConfigPath(env));
8649
+ const profileName = options.profileName ?? env.FX_PROFILE ?? config.activeProfile;
8650
+ const profile = profileName ? config.profiles[profileName] : void 0;
8651
+ const apiUrl = options.apiUrl ?? env.FX_API_URL ?? profile?.apiUrl;
8652
+ const apiKey = options.apiKey ?? env.FX_API_KEY ?? profile?.apiKey;
8653
+ const tenantId = options.tenantId ?? env.FX_ORG_ID ?? profile?.orgId;
8654
+ const bearerToken = options.bearerToken ?? (apiUrl ? await resolveGatewayBearer(apiUrl, {
8655
+ env,
8656
+ databricksProfile: profile?.databricksProfile,
8657
+ tokenProvider: options.tokenProvider
8658
+ }) : void 0);
8659
+ return { profileName, apiUrl, apiKey, tenantId, bearerToken };
8660
+ }
8661
+ async function resolveStudioApiUrl(studioUrl, fetchImpl = globalThis.fetch) {
8662
+ const source = new URL(studioUrl);
8663
+ const response = await fetchImpl(source.toString(), { method: "HEAD", redirect: "manual" });
8664
+ const location = response.headers.get("location");
8665
+ const target = location ? new URL(location, source) : source;
8666
+ target.pathname = "/api";
8667
+ target.search = "";
8668
+ target.hash = "";
8669
+ return target.toString().replace(/\/$/, "");
8670
+ }
8671
+ async function resolveGatewayBearer(apiUrl, options = {}) {
8672
+ const env = options.env ?? process.env;
8673
+ if (env.FX_GATEWAY_BEARER_TOKEN) return env.FX_GATEWAY_BEARER_TOKEN;
8674
+ if (!new URL(apiUrl).hostname.endsWith(".databricksapps.com")) return void 0;
8675
+ const databricksProfile = options.databricksProfile ?? env.FX_DATABRICKS_PROFILE;
8676
+ if (databricksProfile) {
8677
+ return (options.tokenProvider ?? databricksCliToken)(databricksProfile);
8678
+ }
8679
+ const host = env.DATABRICKS_HOST?.replace(/\/$/, "");
8680
+ const clientId = env.FX_QUALITY_DATABRICKS_CLIENT_ID ?? env.DATABRICKS_CLIENT_ID;
8681
+ const clientSecret = env.FX_QUALITY_DATABRICKS_CLIENT_SECRET ?? env.DATABRICKS_CLIENT_SECRET;
8682
+ if (!host || !clientId || !clientSecret) {
8683
+ try {
8684
+ return await (options.tokenProvider ?? databricksCliToken)();
8685
+ } catch {
8686
+ throw new Error(
8687
+ "Databricks Apps access requires a Databricks CLI login, --databricks-profile, FX_DATABRICKS_PROFILE, or DATABRICKS_HOST with client credentials"
8688
+ );
8689
+ }
8690
+ }
8691
+ const response = await fetch(`${host}/oidc/v1/token`, {
8692
+ method: "POST",
8693
+ headers: {
8694
+ authorization: `Basic ${Buffer.from(`${clientId}:${clientSecret}`).toString("base64")}`,
8695
+ "content-type": "application/x-www-form-urlencoded"
8696
+ },
8697
+ body: new URLSearchParams({ grant_type: "client_credentials", scope: "all-apis" })
8698
+ });
8699
+ if (!response.ok) {
8700
+ throw new Error(`Databricks OAuth failed (${response.status} ${response.statusText})`);
8701
+ }
8702
+ const body = await response.json();
8703
+ if (typeof body.access_token !== "string" || !body.access_token) {
8704
+ throw new Error("Databricks OAuth response did not include an access token");
8705
+ }
8706
+ return body.access_token;
8707
+ }
8708
+ async function databricksCliToken(profile) {
8709
+ try {
8710
+ const args = ["auth", "token", ...profile ? [profile] : [], "--output", "json"];
8711
+ const { stdout } = await execFileAsync("databricks", args, { encoding: "utf8" });
8712
+ const parsed = JSON.parse(stdout);
8713
+ if (typeof parsed.access_token !== "string" || !parsed.access_token) {
8714
+ throw new Error("token response did not include access_token");
8715
+ }
8716
+ return parsed.access_token;
8717
+ } catch (error) {
8718
+ throw new Error(
8719
+ `Unable to obtain a Databricks token${profile ? ` for profile ${profile}` : ""}: ${error.message}`
8720
+ );
8721
+ }
8722
+ }
8723
+
8724
+ // src/commands/test-publish.ts
8527
8725
  async function cmdTestPublish(evidencePath, options = {}) {
8528
8726
  const env = options.env ?? process.env;
8529
8727
  const apiUrl = options.apiUrl ?? env.FX_API_URL;
@@ -8552,30 +8750,7 @@ async function cmdTestPublish(evidencePath, options = {}) {
8552
8750
  return 0;
8553
8751
  }
8554
8752
  async function resolveGatewayToken(apiUrl, env) {
8555
- if (env.FX_GATEWAY_BEARER_TOKEN) return env.FX_GATEWAY_BEARER_TOKEN;
8556
- if (!new URL(apiUrl).hostname.endsWith(".databricksapps.com")) return void 0;
8557
- const host = env.DATABRICKS_HOST?.replace(/\/$/, "");
8558
- const clientId = env.FX_QUALITY_DATABRICKS_CLIENT_ID ?? env.DATABRICKS_CLIENT_ID;
8559
- const clientSecret = env.FX_QUALITY_DATABRICKS_CLIENT_SECRET ?? env.DATABRICKS_CLIENT_SECRET;
8560
- if (!host || !clientId || !clientSecret) {
8561
- throw new Error("Databricks Apps publication requires DATABRICKS_HOST and client credentials");
8562
- }
8563
- const response = await fetch(`${host}/oidc/v1/token`, {
8564
- method: "POST",
8565
- headers: {
8566
- authorization: `Basic ${Buffer.from(`${clientId}:${clientSecret}`).toString("base64")}`,
8567
- "content-type": "application/x-www-form-urlencoded"
8568
- },
8569
- body: new URLSearchParams({ grant_type: "client_credentials", scope: "all-apis" })
8570
- });
8571
- if (!response.ok) {
8572
- throw new Error(`Databricks OAuth failed (${response.status} ${response.statusText})`);
8573
- }
8574
- const body = await response.json();
8575
- if (typeof body.access_token !== "string" || !body.access_token) {
8576
- throw new Error("Databricks OAuth response did not include an access token");
8577
- }
8578
- return body.access_token;
8753
+ return resolveGatewayBearer(apiUrl, { env });
8579
8754
  }
8580
8755
  function normalizeTestEvidence(value, options = {}) {
8581
8756
  if (!value || typeof value !== "object") throw new Error("Evidence must be a JSON object");
@@ -8809,6 +8984,188 @@ function isoOrNull(value) {
8809
8984
  if (typeof value !== "string" || Number.isNaN(Date.parse(value))) return null;
8810
8985
  return new Date(value).toISOString();
8811
8986
  }
8987
+ async function cmdLogin(options = {}) {
8988
+ const env = options.env ?? process.env;
8989
+ const profileName = options.profileName ?? "production";
8990
+ const apiUrl = options.apiUrl ? normalizeApiUrl(options.apiUrl) : await resolveStudioApiUrl(
8991
+ options.studioUrl ?? "https://studio.experiments.fabric.pro",
8992
+ options.fetchImpl
8993
+ );
8994
+ const apiKey = options.apiKey ?? env.FX_API_KEY ?? await (options.promptSecret ?? readSecretApiKey)();
8995
+ if (!apiKey) throw new Error("A Fabric API key is required");
8996
+ const bearerToken = await resolveGatewayBearer(apiUrl, {
8997
+ env,
8998
+ databricksProfile: options.databricksProfile,
8999
+ tokenProvider: options.tokenProvider
9000
+ });
9001
+ const client = new ApiClient({
9002
+ baseUrl: apiUrl,
9003
+ apiKey,
9004
+ bearerToken,
9005
+ fetchImpl: options.fetchImpl
9006
+ });
9007
+ const tenant = await client.tenants.me();
9008
+ if (options.tenantId && options.tenantId !== tenant.organization.id) {
9009
+ throw new Error(
9010
+ `API key belongs to ${tenant.organization.id}, not requested organization ${options.tenantId}`
9011
+ );
9012
+ }
9013
+ const now3 = (/* @__PURE__ */ new Date()).toISOString();
9014
+ const path = options.configPath ?? defaultConfigPath(env);
9015
+ const config = await loadHostedConfig(path);
9016
+ const existing = config.profiles[profileName];
9017
+ config.profiles[profileName] = {
9018
+ apiUrl,
9019
+ apiKey,
9020
+ orgId: tenant.organization.id,
9021
+ organizationName: tenant.organization.name,
9022
+ organizationSlug: tenant.organization.slug,
9023
+ role: tenant.member.role,
9024
+ databricksProfile: options.databricksProfile,
9025
+ createdAt: existing?.createdAt ?? now3,
9026
+ updatedAt: now3
9027
+ };
9028
+ config.activeProfile = profileName;
9029
+ await saveHostedConfig(config, path);
9030
+ process.stdout.write(
9031
+ `Logged in to ${tenant.organization.name} as ${tenant.member.role} (profile: ${profileName}).
9032
+ `
9033
+ );
9034
+ return 0;
9035
+ }
9036
+ async function cmdLogout(profileName, options = {}) {
9037
+ const env = options.env ?? process.env;
9038
+ const path = options.configPath ?? defaultConfigPath(env);
9039
+ const config = await loadHostedConfig(path);
9040
+ const target = profileName ?? config.activeProfile;
9041
+ if (!target) {
9042
+ process.stdout.write("No Fabric CLI profile is configured.\n");
9043
+ return 0;
9044
+ }
9045
+ const removed = await removeHostedProfile(target, path);
9046
+ process.stdout.write(
9047
+ removed ? `Logged out profile ${target}.
9048
+ ` : `Profile ${target} not found.
9049
+ `
9050
+ );
9051
+ return removed ? 0 : 1;
9052
+ }
9053
+ async function cmdProfile(action = "list", profileName, options = {}) {
9054
+ const env = options.env ?? process.env;
9055
+ const path = options.configPath ?? defaultConfigPath(env);
9056
+ const config = await loadHostedConfig(path);
9057
+ if (action === "use") {
9058
+ if (!profileName || !config.profiles[profileName]) {
9059
+ process.stderr.write("Usage: fx profile use <name>\n");
9060
+ return 1;
9061
+ }
9062
+ config.activeProfile = profileName;
9063
+ await saveHostedConfig(config, path);
9064
+ process.stdout.write(`Active profile: ${profileName}
9065
+ `);
9066
+ return 0;
9067
+ }
9068
+ if (action === "show") {
9069
+ const selected = profileName ?? config.activeProfile;
9070
+ const profile = selected ? config.profiles[selected] : void 0;
9071
+ if (!selected || !profile) {
9072
+ process.stderr.write("No active Fabric CLI profile. Run fx login.\n");
9073
+ return 1;
9074
+ }
9075
+ process.stdout.write(formatProfile(selected, profile, selected === config.activeProfile));
9076
+ return 0;
9077
+ }
9078
+ const names = Object.keys(config.profiles).sort();
9079
+ if (names.length === 0) {
9080
+ process.stdout.write("No Fabric CLI profiles. Run fx login.\n");
9081
+ return 0;
9082
+ }
9083
+ for (const name of names) {
9084
+ process.stdout.write(
9085
+ formatProfile(name, config.profiles[name], name === config.activeProfile)
9086
+ );
9087
+ }
9088
+ return 0;
9089
+ }
9090
+ async function cmdDoctor(options = {}) {
9091
+ const env = options.env ?? process.env;
9092
+ const path = options.configPath ?? defaultConfigPath(env);
9093
+ const context = await resolveHostedContext({
9094
+ profileName: options.profileName,
9095
+ env,
9096
+ configPath: path,
9097
+ tokenProvider: options.tokenProvider
9098
+ });
9099
+ if (!context.apiUrl || !context.apiKey || !context.tenantId) {
9100
+ process.stderr.write("No complete hosted profile. Run fx login.\n");
9101
+ return 1;
9102
+ }
9103
+ const client = new ApiClient({
9104
+ baseUrl: context.apiUrl,
9105
+ apiKey: context.apiKey,
9106
+ bearerToken: context.bearerToken,
9107
+ defaultOrgId: context.tenantId,
9108
+ fetchImpl: options.fetchImpl
9109
+ });
9110
+ const tenant = await client.tenants.me();
9111
+ const privatePermissions = await configPermissionsArePrivate(path);
9112
+ process.stdout.write(
9113
+ [
9114
+ "Fabric CLI doctor",
9115
+ ` Profile: ${context.profileName ?? "(environment)"}`,
9116
+ ` API: ${context.apiUrl}`,
9117
+ ` Organization: ${tenant.organization.name} (${tenant.organization.id})`,
9118
+ ` Role: ${tenant.member.role}`,
9119
+ ` Gateway: ${context.bearerToken ? "authenticated" : "not required"}`,
9120
+ ` Config mode: ${privatePermissions ? "private" : "INSECURE"}`,
9121
+ ""
9122
+ ].join("\n")
9123
+ );
9124
+ return privatePermissions ? 0 : 2;
9125
+ }
9126
+ function normalizeApiUrl(value) {
9127
+ const url = new URL(value);
9128
+ if (!url.pathname || url.pathname === "/") url.pathname = "/api";
9129
+ return url.toString().replace(/\/$/, "");
9130
+ }
9131
+ function formatProfile(name, profile, active) {
9132
+ return `${active ? "*" : " "} ${name} \u2014 ${profile.organizationName ?? profile.orgId} (${profile.role ?? "unknown"})
9133
+ ${profile.apiUrl}
9134
+ `;
9135
+ }
9136
+ async function readSecretApiKey() {
9137
+ if (!stdin.isTTY || typeof stdin.setRawMode !== "function") {
9138
+ throw new Error("Set FX_API_KEY or pass --api-key when stdin is not interactive");
9139
+ }
9140
+ stderr.write("Fabric API key: ");
9141
+ stdin.setRawMode(true);
9142
+ stdin.resume();
9143
+ return new Promise((resolve11, reject) => {
9144
+ let value = "";
9145
+ const onData = (chunk) => {
9146
+ const text = chunk.toString("utf8");
9147
+ if (text === "") {
9148
+ cleanup();
9149
+ reject(new Error("Login canceled"));
9150
+ return;
9151
+ }
9152
+ if (text === "\r" || text === "\n") {
9153
+ cleanup();
9154
+ stderr.write("\n");
9155
+ resolve11(value.trim());
9156
+ return;
9157
+ }
9158
+ if (text === "\x7F") value = value.slice(0, -1);
9159
+ else value += text;
9160
+ };
9161
+ const cleanup = () => {
9162
+ stdin.off("data", onData);
9163
+ stdin.setRawMode(false);
9164
+ stdin.pause();
9165
+ };
9166
+ stdin.on("data", onData);
9167
+ });
9168
+ }
8812
9169
 
8813
9170
  // src/bin/fx.ts
8814
9171
  var HELP = `fx \u2014 Fabric Experiments CLI
@@ -8830,6 +9187,10 @@ COMMANDS
8830
9187
  test env <action> Create, destroy, list, or reap Databricks test environments.
8831
9188
  test publish <file> Publish BDD/live/JUnit/CLI evidence to Studio Quality.
8832
9189
  init databricks-tests Scaffold a Databricks BDD test project.
9190
+ login Configure and verify a secure hosted profile.
9191
+ logout [profile] Remove a stored hosted profile.
9192
+ profile [list|show|use] Inspect or switch hosted profiles.
9193
+ doctor Verify API, tenant, gateway, role, and config security.
8833
9194
 
8834
9195
  GLOBAL FLAGS
8835
9196
  --tenant <id> Tenant scope (default: default)
@@ -8846,6 +9207,9 @@ GLOBAL FLAGS
8846
9207
  --static <dir> publish: write signed manifest + tag-loader bundle to <dir>
8847
9208
  --api-url <url> push/preview/test publish: hosted API base URL
8848
9209
  --api-key <key> push/preview/test publish: hosted API key
9210
+ --profile <name> hosted profile (default: active profile)
9211
+ --studio-url <url> login: branded Studio URL
9212
+ --databricks-profile <p> login: Databricks CLI profile used for Apps OAuth
8849
9213
  --no-publish push: apply actions without publishing manifest
8850
9214
  --name <name> test env: environment name (for example pr-1234)
8851
9215
  --seed <dir> test env create: JSON fixture directory
@@ -8864,7 +9228,7 @@ GLOBAL FLAGS
8864
9228
  -h, --help print this help
8865
9229
  -v, --version print version
8866
9230
  `;
8867
- var VERSION2 = "0.6.5";
9231
+ var VERSION2 = "0.7.0";
8868
9232
  function parse2(argv) {
8869
9233
  const positional = [];
8870
9234
  const flags = {};
@@ -8909,13 +9273,32 @@ async function main() {
8909
9273
  `);
8910
9274
  return 0;
8911
9275
  }
8912
- const tenantId = args.flags.tenant ?? "default";
9276
+ const explicitTenantId = args.flags.tenant;
9277
+ const tenantId = explicitTenantId ?? "default";
8913
9278
  const allowDeletes = args.flags["allow-deletes"] === true;
8914
9279
  switch (args.command) {
8915
9280
  case "":
8916
9281
  case "help":
8917
9282
  process.stdout.write(HELP);
8918
9283
  return 0;
9284
+ case "login":
9285
+ return cmdLogin({
9286
+ profileName: args.flags.profile,
9287
+ studioUrl: args.flags["studio-url"],
9288
+ apiUrl: args.flags["api-url"],
9289
+ apiKey: args.flags["api-key"],
9290
+ tenantId: explicitTenantId,
9291
+ databricksProfile: args.flags["databricks-profile"]
9292
+ });
9293
+ case "logout":
9294
+ return cmdLogout(args.positional[0] ?? args.flags.profile);
9295
+ case "profile":
9296
+ return cmdProfile(
9297
+ args.positional[0] ?? "list",
9298
+ args.positional[1] ?? args.flags.profile
9299
+ );
9300
+ case "doctor":
9301
+ return cmdDoctor({ profileName: args.flags.profile });
8919
9302
  case "validate":
8920
9303
  return cmdValidate(args.positional[0] ?? ".");
8921
9304
  case "plan":
@@ -8934,17 +9317,25 @@ async function main() {
8934
9317
  dryRun: args.flags["dry-run"] === true,
8935
9318
  allowDeletes
8936
9319
  });
8937
- case "push":
9320
+ case "push": {
9321
+ const hosted = await resolveHostedContext({
9322
+ profileName: args.flags.profile,
9323
+ apiUrl: args.flags["api-url"],
9324
+ apiKey: args.flags["api-key"],
9325
+ tenantId: explicitTenantId
9326
+ });
8938
9327
  return cmdPush(args.positional[0] ?? ".", {
8939
- tenantId,
9328
+ tenantId: hosted.tenantId,
8940
9329
  ownerId: args.flags.owner,
8941
9330
  approverId: args.flags.approver,
8942
9331
  dryRun: args.flags["dry-run"] === true,
8943
9332
  allowDeletes,
8944
- apiUrl: args.flags["api-url"],
8945
- apiKey: args.flags["api-key"],
9333
+ apiUrl: hosted.apiUrl,
9334
+ apiKey: hosted.apiKey,
9335
+ bearerToken: hosted.bearerToken,
8946
9336
  publish: args.flags["no-publish"] !== true
8947
9337
  });
9338
+ }
8948
9339
  case "dev":
8949
9340
  return cmdDev({
8950
9341
  port: args.flags.port ? Number(args.flags.port) : void 0,
@@ -8987,32 +9378,47 @@ async function main() {
8987
9378
  outputDir: args.flags.out,
8988
9379
  reportFile: args.flags.report,
8989
9380
  strict: args.flags.strict === true});
8990
- case "preview":
9381
+ case "preview": {
8991
9382
  if (!args.positional[0]) {
8992
9383
  process.stderr.write(
8993
9384
  "Usage: fx preview <experimentId> --variant <key> [--ttl 900] [--origin https://...] [--api-url ... --api-key ...]\n"
8994
9385
  );
8995
9386
  return 1;
8996
9387
  }
9388
+ const hosted = args.flags.local === true ? {} : await resolveHostedContext({
9389
+ profileName: args.flags.profile,
9390
+ apiUrl: args.flags["api-url"],
9391
+ apiKey: args.flags["api-key"],
9392
+ tenantId: explicitTenantId
9393
+ });
8997
9394
  return cmdPreview(args.positional[0], {
8998
- tenantId,
9395
+ tenantId: hosted.tenantId ?? tenantId,
8999
9396
  variantKey: typeof args.flags.variant === "string" ? args.flags.variant : "",
9000
9397
  ttlSeconds: args.flags.ttl ? Number(args.flags.ttl) : void 0,
9001
9398
  origin: args.flags.origin,
9002
- apiUrl: args.flags["api-url"],
9003
- apiKey: args.flags["api-key"],
9399
+ apiUrl: hosted.apiUrl,
9400
+ apiKey: hosted.apiKey,
9401
+ bearerToken: hosted.bearerToken,
9004
9402
  local: args.flags.local === true
9005
9403
  });
9404
+ }
9006
9405
  case "test":
9007
9406
  if (args.positional[0] === "publish") {
9008
9407
  if (!args.positional[1]) {
9009
9408
  process.stderr.write("Usage: fx test publish <evidence.json|junit.xml> [flags]\n");
9010
9409
  return 1;
9011
9410
  }
9012
- return cmdTestPublish(args.positional[1], {
9013
- tenantId,
9411
+ const hosted = await resolveHostedContext({
9412
+ profileName: args.flags.profile,
9014
9413
  apiUrl: args.flags["api-url"],
9015
9414
  apiKey: args.flags["api-key"],
9415
+ tenantId: explicitTenantId
9416
+ });
9417
+ return cmdTestPublish(args.positional[1], {
9418
+ tenantId: hosted.tenantId,
9419
+ apiUrl: hosted.apiUrl,
9420
+ apiKey: hosted.apiKey,
9421
+ bearerToken: hosted.bearerToken,
9016
9422
  suite: args.flags.suite,
9017
9423
  externalId: args.flags["external-id"],
9018
9424
  runUrl: args.flags["run-url"]