@diafunc/cli 0.5.0 → 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.
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  package_default
3
- } from "./chunk-BQ453MK3.js";
3
+ } from "./chunk-QAMANXTQ.js";
4
4
 
5
5
  // src/index.ts
6
6
  import { Command } from "commander";
@@ -110,14 +110,14 @@ function getAuthHeader(auth) {
110
110
  if (auth.type === "api-token") {
111
111
  return `Bearer ${auth.token}`;
112
112
  }
113
- if (auth.type === "session" || auth.type === "device-code") {
113
+ if (auth.type === "device-code") {
114
114
  return `Bearer ${auth.accessToken}`;
115
115
  }
116
116
  return void 0;
117
117
  }
118
118
  function isTokenExpired(auth) {
119
119
  if (!auth) return false;
120
- if (auth.type === "session" || auth.type === "device-code") {
120
+ if (auth.type === "device-code") {
121
121
  return Date.now() >= auth.accessTokenExpiry - 3e4;
122
122
  }
123
123
  return false;
@@ -132,22 +132,6 @@ function deriveAuthUrl(endpoint) {
132
132
  url.pathname = "";
133
133
  return url.toString().replace(/\/+$/, "");
134
134
  }
135
- async function refreshSession(endpoint, refreshToken) {
136
- const url = `${endpoint}/api/v1/admin/sessions/`;
137
- const response = await fetch(url, {
138
- method: "PUT",
139
- headers: { "Content-Type": "text/plain" },
140
- body: refreshToken
141
- });
142
- if (!response.ok) {
143
- throw new ApiError(response.status, "Session refresh failed. Please log in again.");
144
- }
145
- const session = await response.json();
146
- return {
147
- accessToken: session.accessToken.raw,
148
- accessTokenExpiry: session.accessToken.expiry
149
- };
150
- }
151
135
  async function refreshOAuthTokens(endpoint, clientId, refreshToken) {
152
136
  const authUrl = deriveAuthUrl(endpoint);
153
137
  const response = await fetch(`${authUrl}/token`, {
@@ -177,16 +161,7 @@ async function ensureValidAuth(config, profileOverride) {
177
161
  return profile.auth;
178
162
  }
179
163
  const endpoint = resolveEndpoint(config, profileOverride);
180
- if (profile.auth.type === "session") {
181
- const refreshed = await refreshSession(endpoint, profile.auth.refreshToken);
182
- profile.auth = {
183
- type: "session",
184
- accessToken: refreshed.accessToken,
185
- refreshToken: profile.auth.refreshToken,
186
- accessTokenExpiry: refreshed.accessTokenExpiry
187
- };
188
- saveConfig(config);
189
- } else if (profile.auth.type === "device-code") {
164
+ if (profile.auth.type === "device-code") {
190
165
  const refreshed = await refreshOAuthTokens(endpoint, profile.auth.clientId, profile.auth.refreshToken);
191
166
  profile.auth = {
192
167
  type: "device-code",
@@ -664,7 +639,7 @@ function deriveAuthUrl2(endpoint) {
664
639
  return url.toString().replace(/\/+$/, "");
665
640
  }
666
641
  function registerLoginCommand(parent) {
667
- parent.command("login").description("Authenticate with the Diafunc platform").option("--token <token>", "API token (dfat_...) for non-interactive token-based auth").option("--endpoint <url>", "Override the endpoint URL for this login").option("--password", "Use legacy username/password login instead of OIDC device code").action(async (options) => {
642
+ parent.command("login").description("Authenticate with the Diafunc platform").option("--token <token>", "API token (dfat_...) for non-interactive token-based auth").option("--endpoint <url>", "Override the endpoint URL for this login").action(async (options) => {
668
643
  try {
669
644
  const config = loadConfig();
670
645
  const profile = config.profiles[config.currentProfile];
@@ -688,10 +663,6 @@ function registerLoginCommand(parent) {
688
663
  console.log(` Endpoint: ${profile.endpoint}`);
689
664
  return;
690
665
  }
691
- if (options.password) {
692
- await legacyPasswordLogin(config, profile);
693
- return;
694
- }
695
666
  await deviceCodeLogin(config, profile);
696
667
  } catch (error) {
697
668
  handleError(error);
@@ -771,38 +742,6 @@ Device-code flow failed: ${errorBody.error}${errorBody.error_description ? " \u2
771
742
  console.error(chalk2.red("\nTimed out waiting for approval."));
772
743
  process.exit(1);
773
744
  }
774
- async function legacyPasswordLogin(config, profile) {
775
- const { input, password } = await import("@inquirer/prompts");
776
- const username = await input({ message: "Username or email:" });
777
- const pwd = await password({ message: "Password:" });
778
- const endpoint = profile.endpoint.replace(/\/+$/, "");
779
- const response = await fetch(`${endpoint}/api/v1/admin/sessions/`, {
780
- method: "POST",
781
- headers: { "Content-Type": "application/json" },
782
- body: JSON.stringify({ userNameOrEmail: username, password: pwd })
783
- });
784
- if (!response.ok) {
785
- const text = await response.text();
786
- console.error(chalk2.red("Login failed:"), text || response.statusText);
787
- process.exit(1);
788
- }
789
- const session = await response.json();
790
- profile.auth = {
791
- type: "session",
792
- accessToken: session.accessToken.raw,
793
- refreshToken: session.refreshToken.raw,
794
- accessTokenExpiry: session.accessToken.expiry
795
- };
796
- saveConfig(config);
797
- const client = createHttpClient();
798
- const admin = createAdminService(client);
799
- const user = await admin.getMyUser();
800
- console.log(chalk2.green("Logged in successfully (legacy password path)."));
801
- console.log(` User: ${chalk2.bold(user.name)}`);
802
- console.log(` Email: ${user.email}`);
803
- console.log(` Profile: ${config.currentProfile}`);
804
- console.log(` Endpoint: ${profile.endpoint}`);
805
- }
806
745
  function sleep(ms) {
807
746
  return new Promise((resolve) => setTimeout(resolve, ms));
808
747
  }
@@ -838,18 +777,13 @@ function registerLogoutCommand(parent) {
838
777
  method: "POST",
839
778
  headers: { "Content-Type": "application/x-www-form-urlencoded" },
840
779
  body: new URLSearchParams({
780
+ client_id: profile.auth.clientId,
841
781
  token: profile.auth.refreshToken,
842
782
  token_type_hint: "refresh_token"
843
783
  }).toString()
844
784
  });
845
785
  } catch {
846
786
  }
847
- } else if (profile.auth.type === "session") {
848
- try {
849
- const endpoint = profile.endpoint.replace(/\/+$/, "");
850
- await fetch(`${endpoint}/api/v1/admin/sessions/`, { method: "DELETE" });
851
- } catch {
852
- }
853
787
  }
854
788
  delete profile.auth;
855
789
  saveConfig(config);
@@ -1643,9 +1577,77 @@ function createStorageService(client) {
1643
1577
  path: "/backups/full/restore",
1644
1578
  body: request
1645
1579
  });
1646
- }
1580
+ },
1647
1581
  // --- Event write ops (moved from read-only block) ---
1648
1582
  // NOTE: createEvents / consumeEvents already exist above in the Events section.
1583
+ // --- Data sources ---
1584
+ async createDataSource(request) {
1585
+ return client.request({
1586
+ method: "POST",
1587
+ service: SERVICE3,
1588
+ path: `/data-sources`,
1589
+ body: request
1590
+ });
1591
+ },
1592
+ async listDataSources(projectId) {
1593
+ return client.request({
1594
+ method: "GET",
1595
+ service: SERVICE3,
1596
+ path: `/data-sources`,
1597
+ query: projectId ? { projectId } : void 0
1598
+ });
1599
+ },
1600
+ async getDataSource(id) {
1601
+ return client.request({
1602
+ method: "GET",
1603
+ service: SERVICE3,
1604
+ path: `/data-sources/${enc(id)}`
1605
+ });
1606
+ },
1607
+ async updateDataSource(id, request) {
1608
+ return client.request({
1609
+ method: "PUT",
1610
+ service: SERVICE3,
1611
+ path: `/data-sources/${enc(id)}`,
1612
+ body: request
1613
+ });
1614
+ },
1615
+ async deleteDataSource(id) {
1616
+ await client.request({
1617
+ method: "DELETE",
1618
+ service: SERVICE3,
1619
+ path: `/data-sources/${enc(id)}`
1620
+ });
1621
+ },
1622
+ async refreshDataSource(id) {
1623
+ return client.request({
1624
+ method: "POST",
1625
+ service: SERVICE3,
1626
+ path: `/data-sources/${enc(id)}/refresh`
1627
+ });
1628
+ },
1629
+ async listDataSourceRuns(id, limit) {
1630
+ return client.request({
1631
+ method: "GET",
1632
+ service: SERVICE3,
1633
+ path: `/data-sources/${enc(id)}/runs`,
1634
+ query: limit !== void 0 ? { limit } : void 0
1635
+ });
1636
+ },
1637
+ async getDataSourceRun(id, runId) {
1638
+ return client.request({
1639
+ method: "GET",
1640
+ service: SERVICE3,
1641
+ path: `/data-sources/${enc(id)}/runs/${enc(runId)}`
1642
+ });
1643
+ },
1644
+ async listDataSourceConnectorTypes() {
1645
+ return client.request({
1646
+ method: "GET",
1647
+ service: SERVICE3,
1648
+ path: `/data-sources/types`
1649
+ });
1650
+ }
1649
1651
  };
1650
1652
  }
1651
1653
 
@@ -3693,7 +3695,7 @@ Error: ${event.content}`));
3693
3695
  }
3694
3696
  async function runChatRepl(options) {
3695
3697
  const { input: promptInput } = await import("@inquirer/prompts");
3696
- const { getUpdateNotice } = await import("./update-check-BCZ3WECC.js");
3698
+ const { getUpdateNotice } = await import("./update-check-E3YHFRKF.js");
3697
3699
  let sessionId = options.session;
3698
3700
  console.log(chalk17.bold("Diafunc chat") + chalk17.dim(" \xB7 /help for commands, /quit to exit"));
3699
3701
  if (sessionId) {
@@ -4832,15 +4834,26 @@ async function deleteTrigger(triggerId) {
4832
4834
  await api.analysis.deleteTrigger(triggerId);
4833
4835
  console.log(chalk23.green(`\u2713 Deleted trigger ${triggerId}`));
4834
4836
  }
4835
- async function toggleTrigger(triggerId, active, cmd) {
4837
+ async function updateTriggerCmd(triggerId, options, cmd) {
4836
4838
  const outputFormat = getOutputFormat14(cmd);
4837
- const lc = active.toLowerCase();
4838
- if (lc !== "true" && lc !== "false") {
4839
- console.error(chalk23.red(`Invalid active value "${active}" \u2014 must be true or false.`));
4839
+ let activeFlag;
4840
+ if (options.active !== void 0) {
4841
+ const lc = options.active.toLowerCase();
4842
+ if (lc !== "true" && lc !== "false") {
4843
+ console.error(chalk23.red(`Invalid --active value "${options.active}" \u2014 must be true or false.`));
4844
+ process.exit(1);
4845
+ }
4846
+ activeFlag = lc === "true";
4847
+ }
4848
+ if (activeFlag === void 0 && !options.schedule) {
4849
+ console.error(chalk23.red("Pass at least one of --active or --schedule."));
4840
4850
  process.exit(1);
4841
4851
  }
4842
4852
  const api = createApiClient();
4843
- const trigger = await api.analysis.updateTrigger(triggerId, { active: lc === "true" });
4853
+ const trigger = await api.analysis.updateTrigger(triggerId, {
4854
+ active: activeFlag ?? null,
4855
+ scheduleSpec: options.schedule ?? null
4856
+ });
4844
4857
  format(trigger, { format: outputFormat });
4845
4858
  }
4846
4859
  function registerAnalyzeCommand(program) {
@@ -5104,9 +5117,241 @@ function registerAnalyzeCommand(program) {
5104
5117
  handleError(error);
5105
5118
  }
5106
5119
  });
5107
- triggers.command("toggle").description("Activate or deactivate a trigger").argument("<triggerId>", "Trigger ID").requiredOption("--active <bool>", "true or false").action(async (triggerId, options, cmd) => {
5120
+ triggers.command("update").description("Update a trigger \u2014 pause/resume (--active) and/or reschedule (--schedule)").argument("<triggerId>", "Trigger ID").option("--active <bool>", "true to resume, false to pause").option("--schedule <spec>", "New schedule spec (ISO-8601 instant for ONCE, Quartz cron for CRON)").action(async (triggerId, options, cmd) => {
5108
5121
  try {
5109
- await toggleTrigger(triggerId, options.active, cmd);
5122
+ await updateTriggerCmd(triggerId, options, cmd);
5123
+ } catch (error) {
5124
+ handleError(error);
5125
+ }
5126
+ });
5127
+ }
5128
+
5129
+ // src/commands/data-sources/index.ts
5130
+ import chalk24 from "chalk";
5131
+ function getOutputFormat15(cmd) {
5132
+ const config = loadConfig();
5133
+ const globalOpts = cmd.optsWithGlobals();
5134
+ return globalOpts.output ?? config.defaults.output ?? "human";
5135
+ }
5136
+ function parseConfigPairs(pairs) {
5137
+ const out = {};
5138
+ if (!pairs) return out;
5139
+ for (const pair of pairs) {
5140
+ const idx = pair.indexOf("=");
5141
+ if (idx <= 0) {
5142
+ throw new Error(`Invalid --config "${pair}" \u2014 expected key=value.`);
5143
+ }
5144
+ const key = pair.substring(0, idx).trim();
5145
+ const value = pair.substring(idx + 1);
5146
+ if (!key) {
5147
+ throw new Error(`Invalid --config "${pair}" \u2014 empty key.`);
5148
+ }
5149
+ out[key] = value;
5150
+ }
5151
+ return out;
5152
+ }
5153
+ function dataSourceTableRow(ds) {
5154
+ return {
5155
+ id: ds.id,
5156
+ name: ds.name,
5157
+ type: ds.type,
5158
+ target: `${ds.targetEntityId}@${ds.targetEntityBranch}`,
5159
+ schedule: ds.scheduleCron ?? "manual",
5160
+ lastStatus: ds.lastRunStatus ?? "\u2014",
5161
+ lastRefreshAt: ds.lastRefreshAt ?? "\u2014"
5162
+ };
5163
+ }
5164
+ function runTableRow(run) {
5165
+ return {
5166
+ runId: run.runId,
5167
+ status: run.status,
5168
+ startedAt: run.startedAt ?? "\u2014",
5169
+ finishedAt: run.finishedAt ?? "\u2014",
5170
+ rows: run.rowsImported !== null && run.rowsImported !== void 0 ? String(run.rowsImported) : "\u2014",
5171
+ triggeredBy: run.triggeredBy ?? "\u2014"
5172
+ };
5173
+ }
5174
+ async function listDataSources(projectId, cmd) {
5175
+ const outputFormat = getOutputFormat15(cmd);
5176
+ const api = createApiClient();
5177
+ const sources = await api.storage.listDataSources(projectId);
5178
+ if (outputFormat === "human" && sources.length === 0) {
5179
+ console.log(chalk24.dim("No data sources found."));
5180
+ return;
5181
+ }
5182
+ format(sources.map(dataSourceTableRow), {
5183
+ format: outputFormat,
5184
+ columns: ["id", "name", "type", "target", "schedule", "lastStatus", "lastRefreshAt"]
5185
+ });
5186
+ }
5187
+ async function getDataSource(id, cmd) {
5188
+ const outputFormat = getOutputFormat15(cmd);
5189
+ const api = createApiClient();
5190
+ const ds = await api.storage.getDataSource(id);
5191
+ format(ds, { format: outputFormat });
5192
+ }
5193
+ async function createDataSource(options, cmd) {
5194
+ const outputFormat = getOutputFormat15(cmd);
5195
+ const api = createApiClient();
5196
+ const request = {
5197
+ projectId: options.projectId,
5198
+ projectBranch: options.projectBranch,
5199
+ targetEntityId: options.targetEntityId,
5200
+ targetEntityBranch: options.targetEntityBranch,
5201
+ name: options.name,
5202
+ type: options.type,
5203
+ config: parseConfigPairs(options.config),
5204
+ scheduleCron: options.scheduleCron ?? null
5205
+ };
5206
+ const ds = await api.storage.createDataSource(request);
5207
+ if (outputFormat === "human") {
5208
+ console.log(chalk24.green(`\u2713 Created data source ${ds.id}`));
5209
+ console.log(chalk24.dim(` Last run: ${ds.lastRunStatus ?? "\u2014"}`));
5210
+ if (ds.lastRunError) console.log(chalk24.dim(` Error: ${ds.lastRunError}`));
5211
+ } else {
5212
+ format(ds, { format: outputFormat });
5213
+ }
5214
+ }
5215
+ async function updateDataSource(id, options, cmd) {
5216
+ const outputFormat = getOutputFormat15(cmd);
5217
+ if (options.name === void 0 && options.type === void 0 && (!options.config || options.config.length === 0) && options.scheduleCron === void 0 && !options.clearSchedule) {
5218
+ throw new Error("Provide at least one of --name, --type, --config, --schedule-cron, or --clear-schedule.");
5219
+ }
5220
+ if (options.scheduleCron !== void 0 && options.clearSchedule) {
5221
+ throw new Error("--schedule-cron and --clear-schedule are mutually exclusive.");
5222
+ }
5223
+ let scheduleCron;
5224
+ if (options.clearSchedule) {
5225
+ scheduleCron = "";
5226
+ } else if (options.scheduleCron !== void 0) {
5227
+ scheduleCron = options.scheduleCron;
5228
+ } else {
5229
+ scheduleCron = null;
5230
+ }
5231
+ const request = {
5232
+ name: options.name ?? null,
5233
+ type: options.type ?? null,
5234
+ config: options.config && options.config.length > 0 ? parseConfigPairs(options.config) : null,
5235
+ scheduleCron
5236
+ };
5237
+ const api = createApiClient();
5238
+ const ds = await api.storage.updateDataSource(id, request);
5239
+ if (outputFormat === "human") {
5240
+ console.log(chalk24.green(`\u2713 Updated data source ${ds.id}`));
5241
+ } else {
5242
+ format(ds, { format: outputFormat });
5243
+ }
5244
+ }
5245
+ async function deleteDataSource(id) {
5246
+ const api = createApiClient();
5247
+ await api.storage.deleteDataSource(id);
5248
+ console.log(chalk24.green(`\u2713 Deleted data source ${id}`));
5249
+ }
5250
+ async function refreshDataSource(id, cmd) {
5251
+ const outputFormat = getOutputFormat15(cmd);
5252
+ const api = createApiClient();
5253
+ const run = await api.storage.refreshDataSource(id);
5254
+ if (outputFormat === "human") {
5255
+ console.log(chalk24.green(`\u2713 Refresh queued \u2014 run ${run.runId}, status ${run.status}`));
5256
+ if (run.errorMessage) console.log(chalk24.red(` Error: ${run.errorMessage}`));
5257
+ } else {
5258
+ format(run, { format: outputFormat });
5259
+ }
5260
+ }
5261
+ async function listRuns2(id, limit, cmd) {
5262
+ const outputFormat = getOutputFormat15(cmd);
5263
+ const api = createApiClient();
5264
+ const runs = await api.storage.listDataSourceRuns(id, limit);
5265
+ if (outputFormat === "human" && runs.length === 0) {
5266
+ console.log(chalk24.dim("No runs yet."));
5267
+ return;
5268
+ }
5269
+ format(runs.map(runTableRow), {
5270
+ format: outputFormat,
5271
+ columns: ["runId", "status", "startedAt", "finishedAt", "rows", "triggeredBy"]
5272
+ });
5273
+ }
5274
+ async function getRun(id, runId, cmd) {
5275
+ const outputFormat = getOutputFormat15(cmd);
5276
+ const api = createApiClient();
5277
+ const run = await api.storage.getDataSourceRun(id, runId);
5278
+ format(run, { format: outputFormat });
5279
+ }
5280
+ async function listConnectorTypes(cmd) {
5281
+ const outputFormat = getOutputFormat15(cmd);
5282
+ const api = createApiClient();
5283
+ const types = await api.storage.listDataSourceConnectorTypes();
5284
+ if (outputFormat === "human") {
5285
+ if (types.length === 0) {
5286
+ console.log(chalk24.dim("No connector types registered."));
5287
+ return;
5288
+ }
5289
+ for (const t of types) console.log(t);
5290
+ } else {
5291
+ format(types, { format: outputFormat });
5292
+ }
5293
+ }
5294
+ function registerDataSourcesCommands(program) {
5295
+ const dataSources = program.command("data-sources").description("Manage scheduled DataSource imports (Google Sheets, S3 URL, JDBC)");
5296
+ dataSources.command("list").description("List data sources (optionally scoped to a project)").option("--project-id <id>", "Filter by project ID").action(async (options, cmd) => {
5297
+ try {
5298
+ await listDataSources(options.projectId, cmd);
5299
+ } catch (error) {
5300
+ handleError(error);
5301
+ }
5302
+ });
5303
+ dataSources.command("get").description("Show one data source").argument("<id>", "Data source ID (UUID)").action(async (id, _options, cmd) => {
5304
+ try {
5305
+ await getDataSource(id, cmd);
5306
+ } catch (error) {
5307
+ handleError(error);
5308
+ }
5309
+ });
5310
+ dataSources.command("create").description("Create a data source (runs the initial fetch synchronously)").requiredOption("--project-id <id>", "Project ID").requiredOption("--project-branch <branch>", 'Project branch (usually "main")').requiredOption("--target-entity-id <id>", "Target table entity ID").requiredOption("--target-entity-branch <branch>", "Target table entity branch").requiredOption("--name <name>", "Display name").requiredOption("--type <type>", "Connector type (google_sheets, s3_url, jdbc)").option("--config <key=value>", "Connector config field \u2014 repeat for multiple", (value, prev = []) => prev.concat([value]), []).option("--schedule-cron <expr>", 'Quartz cron expression (e.g. "0 0 2 * * ?" for daily 02:00 UTC); omit for manual-only').action(async (options, cmd) => {
5311
+ try {
5312
+ await createDataSource(options, cmd);
5313
+ } catch (error) {
5314
+ handleError(error);
5315
+ }
5316
+ });
5317
+ dataSources.command("update").description("Update a data source (omit a flag to leave that field unchanged)").argument("<id>", "Data source ID").option("--name <name>", "New display name").option("--type <type>", "New connector type").option("--config <key=value>", 'Replace the entire config map \u2014 repeat for multiple. Send "[redacted]" as a value to keep the existing encrypted credential.', (value, prev = []) => prev.concat([value]), []).option("--schedule-cron <expr>", "New Quartz cron expression").option("--clear-schedule", "Switch this data source to manual-only").action(async (id, options, cmd) => {
5318
+ try {
5319
+ await updateDataSource(id, options, cmd);
5320
+ } catch (error) {
5321
+ handleError(error);
5322
+ }
5323
+ });
5324
+ dataSources.command("delete").description("Delete a data source (existing imported rows are kept)").argument("<id>", "Data source ID").action(async (id) => {
5325
+ try {
5326
+ await deleteDataSource(id);
5327
+ } catch (error) {
5328
+ handleError(error);
5329
+ }
5330
+ });
5331
+ dataSources.command("refresh").description("Trigger an out-of-schedule refresh now").argument("<id>", "Data source ID").action(async (id, _options, cmd) => {
5332
+ try {
5333
+ await refreshDataSource(id, cmd);
5334
+ } catch (error) {
5335
+ handleError(error);
5336
+ }
5337
+ });
5338
+ dataSources.command("runs").description("List recent runs for a data source (newest first)").argument("<id>", "Data source ID").option("--limit <n>", "Max number of runs to show", "20").action(async (id, options, cmd) => {
5339
+ try {
5340
+ await listRuns2(id, parseInt(options.limit, 10), cmd);
5341
+ } catch (error) {
5342
+ handleError(error);
5343
+ }
5344
+ });
5345
+ dataSources.command("run").description("Show one run").argument("<id>", "Data source ID").argument("<runId>", "Run ID").action(async (id, runId, _options, cmd) => {
5346
+ try {
5347
+ await getRun(id, runId, cmd);
5348
+ } catch (error) {
5349
+ handleError(error);
5350
+ }
5351
+ });
5352
+ dataSources.command("types").description("List registered connector types").action(async (_options, cmd) => {
5353
+ try {
5354
+ await listConnectorTypes(cmd);
5110
5355
  } catch (error) {
5111
5356
  handleError(error);
5112
5357
  }
@@ -5367,7 +5612,7 @@ function registerCompletionCommand(program) {
5367
5612
  }
5368
5613
 
5369
5614
  // src/commands/whoami/index.ts
5370
- import chalk24 from "chalk";
5615
+ import chalk25 from "chalk";
5371
5616
  function registerWhoamiCommand(program) {
5372
5617
  program.command("whoami").description("Show the currently authenticated user").action(async (_options, cmd) => {
5373
5618
  try {
@@ -5377,8 +5622,8 @@ function registerWhoamiCommand(program) {
5377
5622
  const api = createApiClient();
5378
5623
  const user = await api.admin.getMyUser();
5379
5624
  if (outputFormat === "human") {
5380
- console.log(chalk24.bold(user.name) + chalk24.dim(` <${user.email}>`));
5381
- console.log(chalk24.dim(` Role: ${user.role} \xB7 Remaining credits: ${user.remainingCredits} \xB7 Profile: ${config.currentProfile}`));
5625
+ console.log(chalk25.bold(user.name) + chalk25.dim(` <${user.email}>`));
5626
+ console.log(chalk25.dim(` Role: ${user.role} \xB7 Remaining credits: ${user.remainingCredits} \xB7 Profile: ${config.currentProfile}`));
5382
5627
  } else {
5383
5628
  format(user, { format: outputFormat });
5384
5629
  }
@@ -5389,8 +5634,8 @@ function registerWhoamiCommand(program) {
5389
5634
  }
5390
5635
 
5391
5636
  // src/commands/utilization/index.ts
5392
- import chalk25 from "chalk";
5393
- function getOutputFormat15(cmd) {
5637
+ import chalk26 from "chalk";
5638
+ function getOutputFormat16(cmd) {
5394
5639
  const config = loadConfig();
5395
5640
  const globalOpts = cmd.optsWithGlobals();
5396
5641
  return globalOpts.output ?? config.defaults.output ?? "human";
@@ -5398,27 +5643,27 @@ function getOutputFormat15(cmd) {
5398
5643
  function printUtilizationHuman(u, label) {
5399
5644
  const when = u.day !== null && u.day !== void 0 ? `${u.year}-${String(u.month).padStart(2, "0")}-${String(u.day).padStart(2, "0")}` : `${u.year}-${String(u.month).padStart(2, "0")}`;
5400
5645
  if (label) {
5401
- console.log(chalk25.bold(label) + " " + chalk25.dim(when));
5646
+ console.log(chalk26.bold(label) + " " + chalk26.dim(when));
5402
5647
  } else {
5403
- console.log(chalk25.bold(when));
5648
+ console.log(chalk26.bold(when));
5404
5649
  }
5405
5650
  if (u.types.length === 0) {
5406
- console.log(chalk25.dim(" (no usage)"));
5651
+ console.log(chalk26.dim(" (no usage)"));
5407
5652
  return;
5408
5653
  }
5409
5654
  for (const t of u.types) {
5410
5655
  console.log(
5411
- ` ${t.type.padEnd(24)} ${chalk25.cyan(String(t.quantity).padStart(10))} ${chalk25.dim("credits:")} ${t.credits.toFixed(2)}`
5656
+ ` ${t.type.padEnd(24)} ${chalk26.cyan(String(t.quantity).padStart(10))} ${chalk26.dim("credits:")} ${t.credits.toFixed(2)}`
5412
5657
  );
5413
5658
  }
5414
5659
  const total = u.totalCredits ?? u.types.reduce((s, t) => s + t.credits, 0);
5415
- console.log(chalk25.bold(` Total credits: ${total.toFixed(2)}`));
5660
+ console.log(chalk26.bold(` Total credits: ${total.toFixed(2)}`));
5416
5661
  }
5417
5662
  function registerUtilizationCommand(program) {
5418
5663
  const util = program.command("utilization").description("Show credit utilization");
5419
5664
  util.command("actual", { isDefault: true }).description("Show current utilization (default subcommand)").action(async (_options, cmd) => {
5420
5665
  try {
5421
- const outputFormat = getOutputFormat15(cmd);
5666
+ const outputFormat = getOutputFormat16(cmd);
5422
5667
  const api = createApiClient();
5423
5668
  const utilization = await api.admin.getActualUtilization();
5424
5669
  if (outputFormat === "human") {
@@ -5432,12 +5677,12 @@ function registerUtilizationCommand(program) {
5432
5677
  });
5433
5678
  util.command("history").description("Show utilization history").action(async (_options, cmd) => {
5434
5679
  try {
5435
- const outputFormat = getOutputFormat15(cmd);
5680
+ const outputFormat = getOutputFormat16(cmd);
5436
5681
  const api = createApiClient();
5437
5682
  const history = await api.admin.getUtilizationHistory();
5438
5683
  if (outputFormat === "human") {
5439
5684
  if (history.length === 0) {
5440
- console.log(chalk25.dim("No usage recorded."));
5685
+ console.log(chalk26.dim("No usage recorded."));
5441
5686
  return;
5442
5687
  }
5443
5688
  for (const u of history) {
@@ -5454,8 +5699,8 @@ function registerUtilizationCommand(program) {
5454
5699
  }
5455
5700
 
5456
5701
  // src/commands/entity-branch/index.ts
5457
- import chalk26 from "chalk";
5458
- function getOutputFormat16(cmd) {
5702
+ import chalk27 from "chalk";
5703
+ function getOutputFormat17(cmd) {
5459
5704
  const config = loadConfig();
5460
5705
  const globalOpts = cmd.optsWithGlobals();
5461
5706
  return globalOpts.output ?? config.defaults.output ?? "human";
@@ -5468,7 +5713,7 @@ function registerEntityBranchCommands(program) {
5468
5713
  const eb = program.command("entity-branch").description("Manage entity branches (parallel versions of a single entity)");
5469
5714
  eb.command("list").description("List branches of an entity").argument("<ref>", "Entity reference (projectId/branch/entityId)").action(async (ref, _options, cmd) => {
5470
5715
  try {
5471
- const outputFormat = getOutputFormat16(cmd);
5716
+ const outputFormat = getOutputFormat17(cmd);
5472
5717
  const overrides = getOverrides9(cmd);
5473
5718
  const resolved = parseEntityReference(ref, overrides);
5474
5719
  const api = createApiClient();
@@ -5498,7 +5743,7 @@ function registerEntityBranchCommands(program) {
5498
5743
  sourceEntityBranch: resolved.entityBranch,
5499
5744
  targetEntityBranch: targetBranch
5500
5745
  });
5501
- console.log(chalk26.green(`Entity branch "${targetBranch}" created from "${resolved.entityBranch}".`));
5746
+ console.log(chalk27.green(`Entity branch "${targetBranch}" created from "${resolved.entityBranch}".`));
5502
5747
  } catch (error) {
5503
5748
  handleError(error);
5504
5749
  }
@@ -5506,7 +5751,7 @@ function registerEntityBranchCommands(program) {
5506
5751
  }
5507
5752
 
5508
5753
  // src/commands/subscription/index.ts
5509
- function getOutputFormat17(cmd) {
5754
+ function getOutputFormat18(cmd) {
5510
5755
  const config = loadConfig();
5511
5756
  const globalOpts = cmd.optsWithGlobals();
5512
5757
  return globalOpts.output ?? config.defaults.output ?? "human";
@@ -5517,7 +5762,7 @@ function registerSubscriptionCommand(program) {
5517
5762
  try {
5518
5763
  const api = createApiClient();
5519
5764
  const s = await api.admin.getCurrentSubscription();
5520
- format(s, { format: getOutputFormat17(cmd) });
5765
+ format(s, { format: getOutputFormat18(cmd) });
5521
5766
  } catch (error) {
5522
5767
  handleError(error);
5523
5768
  }
@@ -5526,7 +5771,7 @@ function registerSubscriptionCommand(program) {
5526
5771
  try {
5527
5772
  const api = createApiClient();
5528
5773
  const s = await api.admin.getNextSubscription();
5529
- format(s, { format: getOutputFormat17(cmd) });
5774
+ format(s, { format: getOutputFormat18(cmd) });
5530
5775
  } catch (error) {
5531
5776
  handleError(error);
5532
5777
  }
@@ -5535,7 +5780,7 @@ function registerSubscriptionCommand(program) {
5535
5780
  try {
5536
5781
  const api = createApiClient();
5537
5782
  const plans = await api.admin.getSubscriptionPlans(subscriptionToken);
5538
- format(plans, { format: getOutputFormat17(cmd) });
5783
+ format(plans, { format: getOutputFormat18(cmd) });
5539
5784
  } catch (error) {
5540
5785
  handleError(error);
5541
5786
  }
@@ -5543,9 +5788,9 @@ function registerSubscriptionCommand(program) {
5543
5788
  }
5544
5789
 
5545
5790
  // src/commands/invoice/index.ts
5546
- import chalk27 from "chalk";
5791
+ import chalk28 from "chalk";
5547
5792
  import * as fs7 from "fs";
5548
- function getOutputFormat18(cmd) {
5793
+ function getOutputFormat19(cmd) {
5549
5794
  const config = loadConfig();
5550
5795
  const globalOpts = cmd.optsWithGlobals();
5551
5796
  return globalOpts.output ?? config.defaults.output ?? "human";
@@ -5557,7 +5802,7 @@ function registerInvoiceCommand(program) {
5557
5802
  const api = createApiClient();
5558
5803
  const invoices = await api.admin.getInvoices();
5559
5804
  format(invoices, {
5560
- format: getOutputFormat18(cmd),
5805
+ format: getOutputFormat19(cmd),
5561
5806
  columns: ["invoiceNumber", "issued", "periodFrom", "periodTo", "total", "status"]
5562
5807
  });
5563
5808
  } catch (error) {
@@ -5571,7 +5816,7 @@ function registerInvoiceCommand(program) {
5571
5816
  const buffer = Buffer.from(await response.arrayBuffer());
5572
5817
  const outPath = options.out ?? fileName;
5573
5818
  fs7.writeFileSync(outPath, buffer);
5574
- console.log(chalk27.green(`Invoice saved to ${outPath}`));
5819
+ console.log(chalk28.green(`Invoice saved to ${outPath}`));
5575
5820
  } catch (error) {
5576
5821
  handleError(error);
5577
5822
  }
@@ -5579,7 +5824,7 @@ function registerInvoiceCommand(program) {
5579
5824
  }
5580
5825
 
5581
5826
  // src/commands/shell/index.ts
5582
- import chalk28 from "chalk";
5827
+ import chalk29 from "chalk";
5583
5828
  import * as fs8 from "fs";
5584
5829
  import * as os3 from "os";
5585
5830
  import * as path6 from "path";
@@ -5645,21 +5890,21 @@ async function evaluate(api, fnRef, language, sourceCode) {
5645
5890
  }, false);
5646
5891
  if (result.outputs?.length) {
5647
5892
  for (const out of result.outputs) {
5648
- console.log(chalk28.dim(` [${out.type}]`) + " " + out.output);
5893
+ console.log(chalk29.dim(` [${out.type}]`) + " " + out.output);
5649
5894
  }
5650
5895
  }
5651
5896
  if (result.successful) {
5652
5897
  if (result.result) {
5653
- console.log(chalk28.green("=> ") + result.result);
5898
+ console.log(chalk29.green("=> ") + result.result);
5654
5899
  } else {
5655
- console.log(chalk28.dim("=> (no value)"));
5900
+ console.log(chalk29.dim("=> (no value)"));
5656
5901
  }
5657
5902
  const duration = result.completed - result.started;
5658
- console.log(chalk28.dim(` [${duration}ms \xB7 ${evaluationId}]`));
5903
+ console.log(chalk29.dim(` [${duration}ms \xB7 ${evaluationId}]`));
5659
5904
  } else {
5660
- console.log(chalk28.red("error: ") + result.error);
5905
+ console.log(chalk29.red("error: ") + result.error);
5661
5906
  if (result.lineNumber > 0) {
5662
- console.log(chalk28.dim(` at line ${result.lineNumber}, col ${result.columnNumber}`));
5907
+ console.log(chalk29.dim(` at line ${result.lineNumber}, col ${result.columnNumber}`));
5663
5908
  }
5664
5909
  }
5665
5910
  }
@@ -5667,9 +5912,9 @@ function registerShellCommand(program) {
5667
5912
  program.command("shell").description("Interactive REPL for function code evaluation").option("--function <ref>", "Function entity reference to use as scratch (required)").option("--language <lang>", "Source language", "JavaScript").action(async (options, cmd) => {
5668
5913
  try {
5669
5914
  if (!options.function) {
5670
- console.error(chalk28.red("Missing --function <ref>."));
5671
- console.error(chalk28.dim("Pass an existing or new function entity reference to use as the shell target."));
5672
- console.error(chalk28.dim("Example: diafunc shell --function my-project/main/scratch/main --language JavaScript"));
5915
+ console.error(chalk29.red("Missing --function <ref>."));
5916
+ console.error(chalk29.dim("Pass an existing or new function entity reference to use as the shell target."));
5917
+ console.error(chalk29.dim("Example: diafunc shell --function my-project/main/scratch/main --language JavaScript"));
5673
5918
  process.exit(1);
5674
5919
  }
5675
5920
  const config = loadConfig();
@@ -5680,18 +5925,18 @@ function registerShellCommand(program) {
5680
5925
  });
5681
5926
  const api = createApiClient();
5682
5927
  const { input: promptInput } = await import("@inquirer/prompts");
5683
- const { getUpdateNotice } = await import("./update-check-BCZ3WECC.js");
5684
- console.log(chalk28.bold("Diafunc shell") + chalk28.dim(` \xB7 function ${fnRef.entityId} \xB7 ${options.language}`));
5685
- console.log(chalk28.dim(`Endpoint: ${config.profiles[config.currentProfile]?.endpoint}`));
5686
- console.log(chalk28.dim("Commands: /edit (multi-line in $EDITOR), /lang <name>, /file <path>, /help, /quit"));
5928
+ const { getUpdateNotice } = await import("./update-check-E3YHFRKF.js");
5929
+ console.log(chalk29.bold("Diafunc shell") + chalk29.dim(` \xB7 function ${fnRef.entityId} \xB7 ${options.language}`));
5930
+ console.log(chalk29.dim(`Endpoint: ${config.profiles[config.currentProfile]?.endpoint}`));
5931
+ console.log(chalk29.dim("Commands: /edit (multi-line in $EDITOR), /lang <name>, /file <path>, /help, /quit"));
5687
5932
  const notice = await getUpdateNotice();
5688
- if (notice) console.log(chalk28.dim(notice));
5933
+ if (notice) console.log(chalk29.dim(notice));
5689
5934
  console.log();
5690
5935
  let language = options.language;
5691
5936
  for (; ; ) {
5692
5937
  let line;
5693
5938
  try {
5694
- line = await promptInput({ message: chalk28.cyan.bold(`${language} >`) });
5939
+ line = await promptInput({ message: chalk29.cyan.bold(`${language} >`) });
5695
5940
  } catch {
5696
5941
  console.log();
5697
5942
  return;
@@ -5709,54 +5954,54 @@ function registerShellCommand(program) {
5709
5954
  case "help":
5710
5955
  case "h":
5711
5956
  case "?":
5712
- console.log(chalk28.dim(" /edit open $EDITOR for multi-line code"));
5713
- console.log(chalk28.dim(" /file <path> evaluate the contents of a file"));
5714
- console.log(chalk28.dim(" /lang <name> switch language (Java, JavaScript, Kotlin, Python, Scala)"));
5715
- console.log(chalk28.dim(" /quit exit the shell"));
5957
+ console.log(chalk29.dim(" /edit open $EDITOR for multi-line code"));
5958
+ console.log(chalk29.dim(" /file <path> evaluate the contents of a file"));
5959
+ console.log(chalk29.dim(" /lang <name> switch language (Java, JavaScript, Kotlin, Python, Scala)"));
5960
+ console.log(chalk29.dim(" /quit exit the shell"));
5716
5961
  continue;
5717
5962
  case "lang":
5718
5963
  if (arg) language = arg;
5719
- console.log(chalk28.dim(`Language: ${language}`));
5964
+ console.log(chalk29.dim(`Language: ${language}`));
5720
5965
  continue;
5721
5966
  case "edit": {
5722
5967
  const sourceCode = await openInEditor("", extensionFor2(language));
5723
5968
  if (!sourceCode.trim()) {
5724
- console.log(chalk28.dim("(empty \u2014 not evaluated)"));
5969
+ console.log(chalk29.dim("(empty \u2014 not evaluated)"));
5725
5970
  continue;
5726
5971
  }
5727
5972
  try {
5728
5973
  await evaluate(api, fnRef, language, sourceCode);
5729
5974
  } catch (e) {
5730
- console.error(chalk28.red(e.message));
5975
+ console.error(chalk29.red(e.message));
5731
5976
  }
5732
5977
  continue;
5733
5978
  }
5734
5979
  case "file": {
5735
5980
  if (!arg) {
5736
- console.log(chalk28.dim("usage: /file <path>"));
5981
+ console.log(chalk29.dim("usage: /file <path>"));
5737
5982
  continue;
5738
5983
  }
5739
5984
  if (!fs8.existsSync(arg)) {
5740
- console.log(chalk28.red(`file not found: ${arg}`));
5985
+ console.log(chalk29.red(`file not found: ${arg}`));
5741
5986
  continue;
5742
5987
  }
5743
5988
  const sourceCode = fs8.readFileSync(arg, "utf-8");
5744
5989
  try {
5745
5990
  await evaluate(api, fnRef, language, sourceCode);
5746
5991
  } catch (e) {
5747
- console.error(chalk28.red(e.message));
5992
+ console.error(chalk29.red(e.message));
5748
5993
  }
5749
5994
  continue;
5750
5995
  }
5751
5996
  default:
5752
- console.log(chalk28.dim(`Unknown command: /${cmd2}. Try /help.`));
5997
+ console.log(chalk29.dim(`Unknown command: /${cmd2}. Try /help.`));
5753
5998
  continue;
5754
5999
  }
5755
6000
  }
5756
6001
  try {
5757
6002
  await evaluate(api, fnRef, language, trimmed);
5758
6003
  } catch (e) {
5759
- console.error(chalk28.red(e.message));
6004
+ console.error(chalk29.red(e.message));
5760
6005
  }
5761
6006
  }
5762
6007
  } catch (error) {
@@ -5766,7 +6011,7 @@ function registerShellCommand(program) {
5766
6011
  }
5767
6012
 
5768
6013
  // src/commands/update/index.ts
5769
- import chalk29 from "chalk";
6014
+ import chalk30 from "chalk";
5770
6015
  import * as path7 from "path";
5771
6016
  import { spawn as spawn4 } from "child_process";
5772
6017
 
@@ -5812,14 +6057,14 @@ function registerUpdateCommand(program) {
5812
6057
  const install = detectInstall();
5813
6058
  const latest = await fetchLatestVersion();
5814
6059
  if (latest === package_default.version) {
5815
- console.log(chalk29.dim(`diafunc is already at the latest version (${package_default.version}).`));
6060
+ console.log(chalk30.dim(`diafunc is already at the latest version (${package_default.version}).`));
5816
6061
  return;
5817
6062
  }
5818
- console.log(chalk29.dim(`Current: ${package_default.version} \u2192 Available: ${latest}`));
6063
+ console.log(chalk30.dim(`Current: ${package_default.version} \u2192 Available: ${latest}`));
5819
6064
  if (install.method === "npm") {
5820
6065
  console.log();
5821
6066
  console.log("Installed via npm. Upgrade with:");
5822
- console.log(chalk29.bold(` npm install -g @diafunc/cli@${latest}`));
6067
+ console.log(chalk30.bold(` npm install -g @diafunc/cli@${latest}`));
5823
6068
  return;
5824
6069
  }
5825
6070
  const installDir = path7.dirname(install.binaryPath);
@@ -5833,7 +6078,7 @@ function registerUpdateCommand(program) {
5833
6078
  }
5834
6079
 
5835
6080
  // src/commands/uninstall/index.ts
5836
- import chalk30 from "chalk";
6081
+ import chalk31 from "chalk";
5837
6082
  import { spawn as spawn5 } from "child_process";
5838
6083
  import * as fs10 from "fs";
5839
6084
  import * as os4 from "os";
@@ -5845,11 +6090,11 @@ function registerUninstallCommand(program) {
5845
6090
  const configDir = path8.join(os4.homedir(), ".diafunc");
5846
6091
  if (install.method === "npm") {
5847
6092
  console.log("Installed via npm. Remove with:");
5848
- console.log(chalk30.bold(" npm uninstall -g @diafunc/cli"));
6093
+ console.log(chalk31.bold(" npm uninstall -g @diafunc/cli"));
5849
6094
  if (fs10.existsSync(configDir)) {
5850
6095
  console.log();
5851
6096
  console.log(`Config + credentials live at ${configDir} \u2014 remove manually with:`);
5852
- console.log(chalk30.bold(` rm -rf ${configDir}`));
6097
+ console.log(chalk31.bold(` rm -rf ${configDir}`));
5853
6098
  }
5854
6099
  return;
5855
6100
  }
@@ -5859,7 +6104,7 @@ function registerUninstallCommand(program) {
5859
6104
  default: false
5860
6105
  });
5861
6106
  if (!removeBinary) {
5862
- console.log(chalk30.dim("Aborted."));
6107
+ console.log(chalk31.dim("Aborted."));
5863
6108
  return;
5864
6109
  }
5865
6110
  let removeConfig = options.purge ?? false;
@@ -5871,7 +6116,7 @@ function registerUninstallCommand(program) {
5871
6116
  }
5872
6117
  if (removeConfig && fs10.existsSync(configDir)) {
5873
6118
  fs10.rmSync(configDir, { recursive: true, force: true });
5874
- console.log(chalk30.dim(`Removed ${configDir}`));
6119
+ console.log(chalk31.dim(`Removed ${configDir}`));
5875
6120
  }
5876
6121
  if (process.platform === "win32") {
5877
6122
  const cmd = `timeout /t 2 /nobreak >nul & del /f /q "${install.binaryPath}"`;
@@ -5881,13 +6126,13 @@ function registerUninstallCommand(program) {
5881
6126
  windowsHide: true
5882
6127
  });
5883
6128
  child.unref();
5884
- console.log(chalk30.dim(`Removing ${install.binaryPath} on exit...`));
6129
+ console.log(chalk31.dim(`Removing ${install.binaryPath} on exit...`));
5885
6130
  console.log();
5886
6131
  console.log("diafunc uninstalled.");
5887
6132
  return;
5888
6133
  }
5889
6134
  fs10.rmSync(install.binaryPath, { force: true });
5890
- console.log(chalk30.dim(`Removed ${install.binaryPath}`));
6135
+ console.log(chalk31.dim(`Removed ${install.binaryPath}`));
5891
6136
  console.log();
5892
6137
  console.log("diafunc uninstalled.");
5893
6138
  } catch (error) {
@@ -5922,6 +6167,7 @@ function createProgram() {
5922
6167
  registerAdminCommands(program);
5923
6168
  registerStatusCommands(program);
5924
6169
  registerAnalyzeCommand(program);
6170
+ registerDataSourcesCommands(program);
5925
6171
  registerCompletionCommand(program);
5926
6172
  registerWhoamiCommand(program);
5927
6173
  registerUtilizationCommand(program);
@@ -5937,4 +6183,4 @@ function createProgram() {
5937
6183
  export {
5938
6184
  createProgram
5939
6185
  };
5940
- //# sourceMappingURL=chunk-BPJNQJQS.js.map
6186
+ //# sourceMappingURL=chunk-L63Y72FJ.js.map