@diafunc/cli 0.9.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,13 +1,13 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  createProgram
4
- } from "../chunk-LTQLKVDU.js";
4
+ } from "../chunk-2WJQPO4V.js";
5
5
  import {
6
6
  getUpdateNotice
7
- } from "../chunk-2JCGI7M5.js";
7
+ } from "../chunk-67PBARIH.js";
8
8
  import {
9
9
  package_default
10
- } from "../chunk-GQBGVUCT.js";
10
+ } from "../chunk-VKUAIYZZ.js";
11
11
 
12
12
  // bin/diafunc.ts
13
13
  import chalk2 from "chalk";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  package_default
3
- } from "./chunk-GQBGVUCT.js";
3
+ } from "./chunk-VKUAIYZZ.js";
4
4
 
5
5
  // src/index.ts
6
6
  import { Command } from "commander";
@@ -71,7 +71,7 @@ var ApiError = class _ApiError extends Error {
71
71
  case 401:
72
72
  return `Authentication failed. Run 'diafunc auth login' to configure your credentials.`;
73
73
  case 403:
74
- return `Permission denied. Your token may not have the required scope.${this.details ? ` (${this.details})` : ""}`;
74
+ return this.message ? `Permission denied: ${this.message}${this.details ? ` (${this.details})` : ""}` : `Permission denied. Your token may not have the required scope.`;
75
75
  case 404:
76
76
  return `Not found: ${this.message}`;
77
77
  case 409:
@@ -243,11 +243,15 @@ ${bodyPreview}`);
243
243
  if (!response.ok) {
244
244
  throw await parseErrorBody(response);
245
245
  }
246
+ if (response.status === 204) {
247
+ return void 0;
248
+ }
246
249
  const contentType = response.headers.get("content-type") ?? "";
250
+ const text = await response.text();
247
251
  if (contentType.includes("application/json")) {
248
- return await response.json();
252
+ return text ? JSON.parse(text) : void 0;
249
253
  }
250
- return await response.text();
254
+ return text;
251
255
  },
252
256
  async requestRaw(opts) {
253
257
  const response = await doRequest(opts);
@@ -885,7 +889,8 @@ import chalk5 from "chalk";
885
889
  // src/output/human.ts
886
890
  import chalk4 from "chalk";
887
891
  import Table from "cli-table3";
888
- function formatHuman(data, columns) {
892
+ function formatHuman(data, columns, dateColumns) {
893
+ const isDate = (key) => dateColumns?.includes(key) ?? false;
889
894
  if (Array.isArray(data)) {
890
895
  if (data.length === 0) {
891
896
  console.log(chalk4.dim("No results."));
@@ -898,7 +903,7 @@ function formatHuman(data, columns) {
898
903
  });
899
904
  for (const row of data) {
900
905
  const r = row;
901
- table.push(cols.map((c) => formatValue(r[c])));
906
+ table.push(cols.map((c) => formatValue(r[c], isDate(c))));
902
907
  }
903
908
  console.log(table.toString());
904
909
  } else if (data && typeof data === "object") {
@@ -907,17 +912,27 @@ function formatHuman(data, columns) {
907
912
  style: { head: [], border: [] }
908
913
  });
909
914
  for (const [key, value] of Object.entries(obj)) {
910
- table.push({ [chalk4.bold(key)]: formatValue(value) });
915
+ table.push({ [chalk4.bold(key)]: formatValue(value, isDate(key)) });
911
916
  }
912
917
  console.log(table.toString());
913
918
  } else {
914
919
  console.log(String(data));
915
920
  }
916
921
  }
917
- function formatValue(value) {
922
+ function formatValue(value, asDate = false) {
918
923
  if (value === null || value === void 0) return chalk4.dim("\u2014");
924
+ if (asDate) return formatInstant(value);
919
925
  if (typeof value === "boolean") return value ? chalk4.green("true") : chalk4.red("false");
920
926
  if (typeof value === "number") return chalk4.cyan(String(value));
927
+ if (typeof value === "object") return JSON.stringify(value);
928
+ return String(value);
929
+ }
930
+ function formatInstant(value) {
931
+ if (value === null || value === void 0) return chalk4.dim("\u2014");
932
+ if (typeof value === "number") {
933
+ const d = new Date(value);
934
+ return Number.isNaN(d.getTime()) ? String(value) : d.toISOString().replace("T", " ").slice(0, 19);
935
+ }
921
936
  return String(value);
922
937
  }
923
938
 
@@ -934,17 +949,22 @@ function formatTable(data, columns) {
934
949
  console.log(cols.join(" "));
935
950
  for (const row of data) {
936
951
  const r = row;
937
- console.log(cols.map((c) => String(r[c] ?? "")).join(" "));
952
+ console.log(cols.map((c) => cell(r[c])).join(" "));
938
953
  }
939
954
  } else if (data && typeof data === "object") {
940
955
  const obj = data;
941
956
  for (const [key, value] of Object.entries(obj)) {
942
- console.log(`${key} ${String(value ?? "")}`);
957
+ console.log(`${key} ${cell(value)}`);
943
958
  }
944
959
  } else {
945
960
  console.log(String(data));
946
961
  }
947
962
  }
963
+ function cell(value) {
964
+ if (value === null || value === void 0) return "";
965
+ if (typeof value === "object") return JSON.stringify(value);
966
+ return String(value);
967
+ }
948
968
 
949
969
  // src/output/formatter.ts
950
970
  function format(data, options) {
@@ -957,7 +977,7 @@ function format(data, options) {
957
977
  break;
958
978
  case "human":
959
979
  default:
960
- formatHuman(data, options.columns);
980
+ formatHuman(data, options.columns, options.dateColumns);
961
981
  break;
962
982
  }
963
983
  }
@@ -2901,6 +2921,31 @@ function parseCount(value, label) {
2901
2921
  }
2902
2922
  return count;
2903
2923
  }
2924
+ function formatMoney(cents, currency) {
2925
+ const sign = cents < 0 ? "-" : "";
2926
+ const abs = Math.abs(cents);
2927
+ return `${sign}${(abs / 100).toFixed(2)} ${currency.toUpperCase()}`;
2928
+ }
2929
+ function printInvoicePreview(preview, outputFormat) {
2930
+ if (outputFormat === "json") {
2931
+ format(preview, { format: outputFormat });
2932
+ return;
2933
+ }
2934
+ format(
2935
+ preview.lineItems.map((item) => ({
2936
+ description: item.description,
2937
+ amount: formatMoney(item.amountCents, preview.currency)
2938
+ })),
2939
+ { format: outputFormat, columns: ["description", "amount"] }
2940
+ );
2941
+ console.log(`Total: ${formatMoney(preview.totalCents, preview.currency)}`);
2942
+ if (preview.nextBillingDate) {
2943
+ const next = preview.nextBillingAmountCents;
2944
+ console.log(
2945
+ `Next bill: ${preview.nextBillingDate}` + (next !== null && next !== void 0 ? ` for ${formatMoney(next, preview.currency)}` : "")
2946
+ );
2947
+ }
2948
+ }
2904
2949
  function registerTeamCommands(program) {
2905
2950
  const team = program.command("team").description("Manage teams: membership, invitations, seats, billing, and ownership");
2906
2951
  team.command("list", { isDefault: true }).description("List the teams you belong to").action(async (_options, cmd) => {
@@ -2909,7 +2954,8 @@ function registerTeamCommands(program) {
2909
2954
  const teams = await api.admin.listMyTeams();
2910
2955
  format(teams, {
2911
2956
  format: getOutputFormat2(cmd),
2912
- columns: ["id", "name", "planId", "seatCount", "packCount", "renewal"]
2957
+ columns: ["id", "name", "planId", "seatCount", "packCount", "renewal"],
2958
+ dateColumns: ["createdAt", "dunningStartedAt"]
2913
2959
  });
2914
2960
  } catch (error) {
2915
2961
  handleError(error);
@@ -2918,7 +2964,10 @@ function registerTeamCommands(program) {
2918
2964
  team.command("get").description("Show a team").argument("<teamId>", "Team ID").action(async (teamId, _options, cmd) => {
2919
2965
  try {
2920
2966
  const api = createApiClient();
2921
- format(await api.admin.getTeam(teamId), { format: getOutputFormat2(cmd) });
2967
+ format(await api.admin.getTeam(teamId), {
2968
+ format: getOutputFormat2(cmd),
2969
+ dateColumns: ["createdAt", "dunningStartedAt"]
2970
+ });
2922
2971
  } catch (error) {
2923
2972
  handleError(error);
2924
2973
  }
@@ -3026,12 +3075,15 @@ function registerTeamCommands(program) {
3026
3075
  }
3027
3076
  function registerMemberCommands(team) {
3028
3077
  const members = team.command("members").description("Manage team members");
3029
- members.command("list", { isDefault: true }).description("List team members").argument("<teamId>", "Team ID").action(async (teamId, _options, cmd) => {
3078
+ members.command("list", { isDefault: true }).description("List team members").argument("<teamId>", "Team ID").option("--all", "Include members who have been removed from the team").action(async (teamId, options, cmd) => {
3030
3079
  try {
3031
3080
  const api = createApiClient();
3032
- format(await api.admin.listTeamMembers(teamId), {
3081
+ const all = await api.admin.listTeamMembers(teamId);
3082
+ const shown = options.all ? all : all.filter((m) => !m.removedAt);
3083
+ format(shown, {
3033
3084
  format: getOutputFormat2(cmd),
3034
- columns: ["userId", "name", "email", "role", "joinedAt"]
3085
+ columns: options.all ? ["userId", "name", "email", "role", "joinedAt", "removedAt"] : ["userId", "name", "email", "role", "joinedAt"],
3086
+ dateColumns: ["joinedAt", "invitedAt", "removedAt"]
3035
3087
  });
3036
3088
  } catch (error) {
3037
3089
  handleError(error);
@@ -3072,7 +3124,8 @@ function registerInvitationCommands(team) {
3072
3124
  const api = createApiClient();
3073
3125
  format(await api.admin.listTeamInvitations(teamId), {
3074
3126
  format: getOutputFormat2(cmd),
3075
- columns: ["invitationId", "email", "role", "invitedBy", "expiresAt"]
3127
+ columns: ["invitationId", "email", "role", "invitedBy", "expiresAt"],
3128
+ dateColumns: ["createdAt", "expiresAt"]
3076
3129
  });
3077
3130
  } catch (error) {
3078
3131
  handleError(error);
@@ -3121,9 +3174,10 @@ function registerSeatCommands(team) {
3121
3174
  seats.command("preview").description("Preview the invoice for a seat-count change without applying it").argument("<teamId>", "Team ID").argument("<count>", "New seat count").action(async (teamId, count, _options, cmd) => {
3122
3175
  try {
3123
3176
  const api = createApiClient();
3124
- format(await api.admin.previewTeamSeatCount(teamId, parseCount(count, "seat count")), {
3125
- format: getOutputFormat2(cmd)
3126
- });
3177
+ printInvoicePreview(
3178
+ await api.admin.previewTeamSeatCount(teamId, parseCount(count, "seat count")),
3179
+ getOutputFormat2(cmd)
3180
+ );
3127
3181
  } catch (error) {
3128
3182
  handleError(error);
3129
3183
  }
@@ -3150,9 +3204,10 @@ function registerPackCommands(team) {
3150
3204
  packs.command("preview").description("Preview the invoice for a pack-count change without applying it").argument("<teamId>", "Team ID").argument("<count>", "New pack count").action(async (teamId, count, _options, cmd) => {
3151
3205
  try {
3152
3206
  const api = createApiClient();
3153
- format(await api.admin.previewTeamPackCount(teamId, parseCount(count, "pack count")), {
3154
- format: getOutputFormat2(cmd)
3155
- });
3207
+ printInvoicePreview(
3208
+ await api.admin.previewTeamPackCount(teamId, parseCount(count, "pack count")),
3209
+ getOutputFormat2(cmd)
3210
+ );
3156
3211
  } catch (error) {
3157
3212
  handleError(error);
3158
3213
  }
@@ -3193,7 +3248,17 @@ function registerOwnershipCommands(team) {
3193
3248
  transfer.command("status", { isDefault: true }).description("Show the pending ownership transfer").argument("<teamId>", "Team ID").action(async (teamId, _options, cmd) => {
3194
3249
  try {
3195
3250
  const api = createApiClient();
3196
- format(await api.admin.getOwnershipTransfer(teamId), { format: getOutputFormat2(cmd) });
3251
+ const pending = await api.admin.getOwnershipTransfer(teamId);
3252
+ const outputFormat = getOutputFormat2(cmd);
3253
+ if (!pending) {
3254
+ if (outputFormat === "json") {
3255
+ format(null, { format: outputFormat });
3256
+ } else {
3257
+ console.log(`No pending ownership transfer for team "${teamId}".`);
3258
+ }
3259
+ return;
3260
+ }
3261
+ format(pending, { format: outputFormat, dateColumns: ["createdAt"] });
3197
3262
  } catch (error) {
3198
3263
  handleError(error);
3199
3264
  }
@@ -3778,8 +3843,8 @@ function registerTableCommands(program) {
3778
3843
  const sortedCols = [...snapshot.columns].sort((a, b) => a.index - b.index);
3779
3844
  const colNames = sortedCols.map((c) => c.name || `col${c.index}`);
3780
3845
  const cellMap = /* @__PURE__ */ new Map();
3781
- for (const cell2 of snapshot.cells) {
3782
- cellMap.set(`${cell2.rowIndex}:${cell2.columnIndex}`, cell2.value ?? "");
3846
+ for (const cell3 of snapshot.cells) {
3847
+ cellMap.set(`${cell3.rowIndex}:${cell3.columnIndex}`, cell3.value ?? "");
3783
3848
  }
3784
3849
  const sortedRows = [...snapshot.rows].sort((a, b) => a.index - b.index);
3785
3850
  const tableData = sortedRows.map((row2) => {
@@ -4095,8 +4160,8 @@ function registerTableCommands(program) {
4095
4160
  handleError(error);
4096
4161
  }
4097
4162
  });
4098
- const cell = table.command("cell").description("Manage table cells");
4099
- cell.command("set").description("Set a cell value").argument("<ref>", "Table entity reference").argument("<row>", "Row index").argument("<col>", "Column index").argument("<value>", "Cell value").action(async (ref, row2, col, value, _options, cmd) => {
4163
+ const cell2 = table.command("cell").description("Manage table cells");
4164
+ cell2.command("set").description("Set a cell value").argument("<ref>", "Table entity reference").argument("<row>", "Row index").argument("<col>", "Column index").argument("<value>", "Cell value").action(async (ref, row2, col, value, _options, cmd) => {
4100
4165
  try {
4101
4166
  const overrides = getOverrides6(cmd);
4102
4167
  const resolved = parseEntityReference(ref, overrides);
@@ -4112,7 +4177,7 @@ function registerTableCommands(program) {
4112
4177
  handleError(error);
4113
4178
  }
4114
4179
  });
4115
- cell.command("delete").description("Delete a cell value").argument("<ref>", "Table entity reference").argument("<row>", "Row index").argument("<col>", "Column index").action(async (ref, row2, col, _options, cmd) => {
4180
+ cell2.command("delete").description("Delete a cell value").argument("<ref>", "Table entity reference").argument("<row>", "Row index").argument("<col>", "Column index").action(async (ref, row2, col, _options, cmd) => {
4116
4181
  try {
4117
4182
  const overrides = getOverrides6(cmd);
4118
4183
  const resolved = parseEntityReference(ref, overrides);
@@ -4928,7 +4993,7 @@ Error: ${event.content}`));
4928
4993
  }
4929
4994
  async function runChatRepl(options) {
4930
4995
  const { input: promptInput } = await import("@inquirer/prompts");
4931
- const { getUpdateNotice } = await import("./update-check-UOHMHDN6.js");
4996
+ const { getUpdateNotice } = await import("./update-check-L55QNPYQ.js");
4932
4997
  let sessionId = options.session;
4933
4998
  console.log(chalk22.bold("Diafunc chat") + chalk22.dim(" \xB7 /help for commands, /quit to exit"));
4934
4999
  if (sessionId) {
@@ -7431,7 +7496,7 @@ function registerShellCommand(program) {
7431
7496
  });
7432
7497
  const api = createApiClient();
7433
7498
  const { input: promptInput } = await import("@inquirer/prompts");
7434
- const { getUpdateNotice } = await import("./update-check-UOHMHDN6.js");
7499
+ const { getUpdateNotice } = await import("./update-check-L55QNPYQ.js");
7435
7500
  console.log(chalk35.bold("Diafunc shell") + chalk35.dim(` \xB7 function ${fnRef.entityId} \xB7 ${options.language}`));
7436
7501
  console.log(chalk35.dim(`Endpoint: ${config.profiles[config.currentProfile]?.endpoint}`));
7437
7502
  console.log(chalk35.dim("Commands: /edit (multi-line in $EDITOR), /lang <name>, /file <path>, /help, /quit"));
@@ -7692,4 +7757,4 @@ function createProgram() {
7692
7757
  export {
7693
7758
  createProgram
7694
7759
  };
7695
- //# sourceMappingURL=chunk-LTQLKVDU.js.map
7760
+ //# sourceMappingURL=chunk-2WJQPO4V.js.map