bamboohr-cli 1.0.19 → 1.0.20-gc408819.2

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.
Files changed (2) hide show
  1. package/dist/index.js +186 -29
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -68,6 +68,58 @@ function positiveInt(raw) {
68
68
  return n;
69
69
  }
70
70
 
71
+ // ../../cli-utils/dist/text-or-file.js
72
+ import { readFileSync as readFileSync3 } from "fs";
73
+ import { InvalidArgumentError as InvalidArgumentError2, Option } from "commander";
74
+ var STDIN_REF = "-";
75
+ function rejectStdinSentinel(value) {
76
+ if (value === "@-" || value === STDIN_REF) {
77
+ throw new InvalidArgumentError2(`"${value}" looks like a stdin redirect, which is not supported here. Pass the text directly, or read it from a file/stdin with the matching --\u2026-file <path|-> option.`);
78
+ }
79
+ return value;
80
+ }
81
+ function readFileOrStdin(ref) {
82
+ if (ref === STDIN_REF) {
83
+ if (process.stdin.isTTY) {
84
+ throw new InvalidArgumentError2('"--\u2026-file -" reads stdin, but stdin is a terminal (nothing piped).');
85
+ }
86
+ try {
87
+ return readFileSync3(0, "utf8");
88
+ } catch (err) {
89
+ throw new InvalidArgumentError2(`failed to read stdin for "--\u2026-file -": ${err.message}`);
90
+ }
91
+ }
92
+ try {
93
+ return readFileSync3(ref, "utf8");
94
+ } catch (err) {
95
+ const e = err;
96
+ if (e.code === "ENOENT") {
97
+ throw new InvalidArgumentError2(`file not found: "${ref}".`);
98
+ }
99
+ throw new InvalidArgumentError2(`failed to read file "${ref}": ${e.message}`);
100
+ }
101
+ }
102
+ function textOrFileOption(cmd, name, opts = {}) {
103
+ const label = `${name.charAt(0).toUpperCase()}${name.slice(1)} content`;
104
+ cmd.option(`--${name} <text>`, opts.description ?? label, rejectStdinSentinel);
105
+ cmd.addOption(new Option(`--${name}-file <path>`, `Read --${name} from a file, or "-" for stdin (mutually exclusive with --${name})`).conflicts(name));
106
+ return cmd;
107
+ }
108
+ function resolveTextOrFile(opts, name, { required = true } = {}) {
109
+ const literal = opts[name];
110
+ const ref = opts[`${name}File`];
111
+ if (literal !== void 0 && ref !== void 0) {
112
+ throw new InvalidArgumentError2(`--${name} and --${name}-file are mutually exclusive; provide only one.`);
113
+ }
114
+ if (ref !== void 0) {
115
+ return readFileOrStdin(ref);
116
+ }
117
+ if (literal === void 0 && required) {
118
+ throw new InvalidArgumentError2(`a ${name} is required: provide --${name} <text> or --${name}-file <path>.`);
119
+ }
120
+ return literal;
121
+ }
122
+
71
123
  // ../../cli-utils/dist/builders.js
72
124
  var EXAMPLES = /* @__PURE__ */ new WeakSet();
73
125
  function commandPath(cmd) {
@@ -496,10 +548,10 @@ function mergeFields(existing, extra) {
496
548
  }
497
549
 
498
550
  // src/commands/employee/goals.ts
499
- import { Option } from "commander";
551
+ import { Option as Option2 } from "commander";
500
552
  var GOAL_FILTERS = ["open", "closed", "all"];
501
553
  function goals(parent) {
502
- const cmd = parent.command("goals <employeeId>").description("Get employee performance goals").addOption(new Option("--filter <filter>", "Filter goals by status").choices(GOAL_FILTERS).default("all"));
554
+ const cmd = parent.command("goals <employeeId>").description("Get employee performance goals").addOption(new Option2("--filter <filter>", "Filter goals by status").choices(GOAL_FILTERS).default("all"));
503
555
  examples(cmd, ["123", ["123 --filter open", "only open goals"], ["123 --filter closed", "only closed goals"]]);
504
556
  cmd.action(async (employeeId, opts) => {
505
557
  const client = getClient();
@@ -513,10 +565,10 @@ function goals(parent) {
513
565
 
514
566
  // src/commands/employee/photo.ts
515
567
  import { writeFileSync as writeFileSync2 } from "fs";
516
- import { Option as Option2 } from "commander";
568
+ import { Option as Option3 } from "commander";
517
569
  var PHOTO_SIZES = ["original", "large", "medium", "small", "xs", "tiny"];
518
570
  function photo(parent) {
519
- const cmd = parent.command("photo <employeeId>").description("Download employee photo").requiredOption("--output <path>", "File path to save photo").addOption(new Option2("--size <size>", "Photo size").choices(PHOTO_SIZES).default("medium"));
571
+ const cmd = parent.command("photo <employeeId>").description("Download employee photo").requiredOption("--output <path>", "File path to save photo").addOption(new Option3("--size <size>", "Photo size").choices(PHOTO_SIZES).default("medium"));
520
572
  examples(cmd, [["123 --output ./photo.jpg", "medium size (default)"], "123 --output ./photo.jpg --size large"]);
521
573
  cmd.action(async (employeeId, opts) => {
522
574
  const client = getClient();
@@ -704,15 +756,83 @@ function balance(parent) {
704
756
  }
705
757
 
706
758
  // src/commands/timeoff/create.ts
707
- import { Option as Option3 } from "commander";
759
+ import { InvalidArgumentError as InvalidArgumentError4, Option as Option4 } from "commander";
760
+
761
+ // src/utils/timeoff-dates.ts
762
+ import { InvalidArgumentError as InvalidArgumentError3 } from "commander";
763
+ var WEEKDAY_NAMES = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
764
+ var YMD = /^\d{4}-\d{2}-\d{2}$/;
765
+ function parseDatesJson(raw) {
766
+ let parsed;
767
+ try {
768
+ parsed = JSON.parse(raw);
769
+ } catch {
770
+ throw new InvalidArgumentError3(
771
+ `--dates is not valid JSON. Expected an array like '[{"ymd":"2026-03-21","amount":0.5}]'.`
772
+ );
773
+ }
774
+ const isEntry = (d) => typeof d === "object" && d !== null && typeof d.ymd === "string" && YMD.test(d.ymd) && typeof d.amount === "number" && Number.isFinite(d.amount) && d.amount >= 0;
775
+ if (!Array.isArray(parsed) || parsed.length === 0 || !parsed.every(isEntry)) {
776
+ throw new InvalidArgumentError3(
777
+ '--dates must be a non-empty JSON array of {"ymd":"YYYY-MM-DD","amount":<non-negative number>} objects.'
778
+ );
779
+ }
780
+ return parsed.map((d) => ({ ymd: d.ymd, amount: d.amount }));
781
+ }
782
+ function parseYmd(value, label) {
783
+ if (!YMD.test(value)) {
784
+ throw new InvalidArgumentError3(`${label} must be a YYYY-MM-DD date, got "${value}".`);
785
+ }
786
+ const date = /* @__PURE__ */ new Date(`${value}T00:00:00Z`);
787
+ if (Number.isNaN(date.getTime())) {
788
+ throw new InvalidArgumentError3(`${label} is not a valid date: "${value}".`);
789
+ }
790
+ return date;
791
+ }
792
+ function toYmd(date) {
793
+ return date.toISOString().slice(0, 10);
794
+ }
795
+ function buildTimeOffDates(params) {
796
+ const { start, end, units, defaultHours, holidays = [] } = params;
797
+ const startDate = parseYmd(start, "--start-date");
798
+ const endDate = parseYmd(end, "--end-date");
799
+ if (endDate < startDate) {
800
+ throw new InvalidArgumentError3(`--end-date ${end} is before --start-date ${start}.`);
801
+ }
802
+ const hoursByName = new Map(defaultHours.map((entry) => [entry.name, Number(entry.amount)]));
803
+ const fallbackHours = hoursByName.get("default") ?? 8;
804
+ const dates = [];
805
+ for (const day = new Date(startDate); day <= endDate; day.setUTCDate(day.getUTCDate() + 1)) {
806
+ const ymd = toYmd(day);
807
+ const workingHours = hoursByName.get(WEEKDAY_NAMES[day.getUTCDay()]) ?? fallbackHours;
808
+ const isHoliday = holidays.some((h) => ymd >= h.start && ymd <= h.end);
809
+ const working = workingHours > 0 && !isHoliday;
810
+ dates.push({ ymd, amount: working ? units === "hours" ? workingHours : 1 : 0 });
811
+ }
812
+ return dates;
813
+ }
814
+
815
+ // src/commands/timeoff/create.ts
708
816
  function create(parent) {
709
- const cmd = parent.command("create [employeeId]").description("Create a time off request (defaults to current user)").requiredOption("--start-date <date>", "Start date (YYYY-MM-DD)").requiredOption("--end-date <date>", "End date (YYYY-MM-DD)").requiredOption("--type-id <id>", 'Time off type ID (use "timeoff types" to find IDs)', positiveInt).requiredOption("--amount <amount>", "Total amount of time off (in days or hours depending on type)", parseFloat).addOption(
710
- new Option3("--status <status>", "Request status").choices(["requested", "approved"]).default("requested")
711
- ).option("--note <text>", "Note to include with the request").option("--dates <json>", `Per-day amounts as JSON array, e.g. '[{"ymd":"2026-03-21","amount":4}]' for half-day`);
817
+ const cmd = parent.command("create [employeeId]").description("Create a time off request (defaults to current user)").requiredOption("--start-date <date>", "Start date (YYYY-MM-DD)").requiredOption("--end-date <date>", "End date (YYYY-MM-DD)").requiredOption("--type-id <id>", 'Time off type ID (use "timeoff types" to find IDs)', positiveInt).option(
818
+ "--amount <amount>",
819
+ "Expected total (days or hours, per the type). Optional sanity check \u2014 the total is computed from the per-day breakdown",
820
+ parseFloat
821
+ ).addOption(
822
+ new Option4("--status <status>", "Request status").choices(["requested", "approved"]).default("requested")
823
+ ).option(
824
+ "--dates <json>",
825
+ `Per-day amounts as JSON array, e.g. '[{"ymd":"2026-03-21","amount":0.5}]' for a half day. When omitted, generated automatically: 1 day (or the weekday's working hours) per working day, 0 on weekends and company holidays`
826
+ );
827
+ textOrFileOption(cmd, "note", { description: "Note to include with the request" });
712
828
  examples(cmd, [
713
- "--start-date 2026-04-01 --end-date 2026-04-01 --type-id 83 --amount 1",
829
+ ["--start-date 2026-04-06 --end-date 2026-04-10 --type-id 83", "a full week off, spread per day automatically"],
714
830
  [
715
- '504 --start-date 2026-04-01 --end-date 2026-04-01 --type-id 83 --amount 1 --note "Doctor appointment"',
831
+ `--start-date 2026-04-01 --end-date 2026-04-01 --type-id 83 --dates '[{"ymd":"2026-04-01","amount":0.5}]'`,
832
+ "a half day"
833
+ ],
834
+ [
835
+ '504 --start-date 2026-04-01 --end-date 2026-04-01 --type-id 83 --note "Doctor appointment"',
716
836
  "for another employee"
717
837
  ]
718
838
  ]);
@@ -720,15 +840,48 @@ function create(parent) {
720
840
  async (employeeId, opts) => {
721
841
  const client = getClient();
722
842
  const id = await resolveEmployeeId(client, employeeId);
843
+ const note = resolveTextOrFile(opts, "note", { required: false });
844
+ let dates;
845
+ if (opts.dates) {
846
+ dates = parseDatesJson(opts.dates);
847
+ } else {
848
+ const [types2, whosOut2] = await Promise.all([
849
+ getTimeOffTypes(client),
850
+ client.timeOff.getWhosOut({ start: opts.startDate, end: opts.endDate })
851
+ ]);
852
+ const type = types2.timeOffTypes.find((t) => Number(t.id) === opts.typeId);
853
+ if (!type) {
854
+ throw new InvalidArgumentError4(`Unknown time off type ID ${opts.typeId}. Run "timeoff types" to list IDs.`);
855
+ }
856
+ const holidays = whosOut2.filter((e) => e.type === "holiday").map((e) => ({ start: e.start, end: e.end }));
857
+ dates = buildTimeOffDates({
858
+ start: opts.startDate,
859
+ end: opts.endDate,
860
+ units: type.units,
861
+ defaultHours: types2.defaultHours,
862
+ holidays
863
+ });
864
+ }
865
+ const total = dates.reduce((sum, d) => sum + d.amount, 0);
866
+ if (total <= 0) {
867
+ throw new InvalidArgumentError4(
868
+ opts.dates ? "The per-day amounts in --dates sum to 0; a request must claim more than 0 days/hours." : "The requested range contains no working days (weekends/company holidays only). Adjust the dates or pass --dates explicitly."
869
+ );
870
+ }
871
+ if (opts.amount !== void 0 && Math.abs(opts.amount - total) > 1e-9) {
872
+ throw new InvalidArgumentError4(
873
+ `--amount ${opts.amount} does not match the per-day total ${total} (working days in range, minus weekends and company holidays). Omit --amount, or pass --dates to set per-day amounts explicitly (e.g. half days).`
874
+ );
875
+ }
723
876
  const result = await client.timeOff.createRequest({
724
877
  employeeId: id,
725
878
  status: opts.status,
726
879
  start: opts.startDate,
727
880
  end: opts.endDate,
728
881
  timeOffTypeId: opts.typeId,
729
- amount: opts.amount,
730
- notes: opts.note ? [{ from: "employee", note: opts.note }] : void 0,
731
- dates: opts.dates ? JSON.parse(opts.dates) : void 0
882
+ amount: total,
883
+ notes: note ? [{ from: "employee", note }] : void 0,
884
+ dates
732
885
  });
733
886
  output(
734
887
  result ? stripNullish(result) : { created: true, employeeId: id, start: opts.startDate, end: opts.endDate }
@@ -738,10 +891,10 @@ function create(parent) {
738
891
  }
739
892
 
740
893
  // src/commands/timeoff/requests.ts
741
- import { Option as Option4 } from "commander";
894
+ import { Option as Option5 } from "commander";
742
895
  function requests(parent) {
743
- const cmd = parent.command("requests").description("Get time off requests (defaults to current user)").option("--request-id <id>", "Specific request ID", positiveInt).addOption(new Option4("--action <action>", "Access level filter").choices(["view", "approve"])).option("--employee-id <id>", "Filter by employee ID").option("--all", "Show all visible requests instead of just current user").option("--start-date <date>", "Start date (YYYY-MM-DD)").option("--end-date <date>", "End date (YYYY-MM-DD)").addOption(
744
- new Option4("--status <status>", "Filter by request status").choices([
896
+ const cmd = parent.command("requests").description("Get time off requests (defaults to current user)").option("--request-id <id>", "Specific request ID", positiveInt).addOption(new Option5("--action <action>", "Access level filter").choices(["view", "approve"])).option("--employee-id <id>", "Filter by employee ID").option("--all", "Show all visible requests instead of just current user").option("--start-date <date>", "Start date (YYYY-MM-DD)").option("--end-date <date>", "End date (YYYY-MM-DD)").addOption(
897
+ new Option5("--status <status>", "Filter by request status").choices([
745
898
  "approved",
746
899
  "denied",
747
900
  "superceded",
@@ -791,25 +944,29 @@ function types(parent) {
791
944
  }
792
945
 
793
946
  // src/commands/timeoff/update-status.ts
794
- import { Option as Option5 } from "commander";
947
+ import { Option as Option6 } from "commander";
795
948
  function updateStatus(parent) {
796
949
  const cmd = parent.command("update-status <requestId>").description("Update time off request status (approve, deny, cancel)").addOption(
797
- new Option5("--status <status>", "New status").choices(["approved", "denied", "canceled"]).makeOptionMandatory()
798
- ).option("--note <text>", "Note to attach to the status change");
950
+ new Option6("--status <status>", "New status").choices(["approved", "denied", "canceled"]).makeOptionMandatory()
951
+ );
952
+ textOrFileOption(cmd, "note", { description: "Note to attach to the status change" });
799
953
  examples(cmd, [
800
954
  "7890 --status approved",
801
955
  ['7890 --status denied --note "Team at capacity that week"', "deny with note"],
802
956
  "7890 --status canceled"
803
957
  ]);
804
- cmd.action(async (requestId, opts) => {
805
- const client = getClient();
806
- const result = await client.timeOff.updateRequestStatus({
807
- requestId,
808
- status: opts.status,
809
- note: opts.note
810
- });
811
- output(result ? stripNullish(result) : { updated: true, requestId, status: opts.status });
812
- });
958
+ cmd.action(
959
+ async (requestId, opts) => {
960
+ const client = getClient();
961
+ const note = resolveTextOrFile(opts, "note", { required: false });
962
+ const result = await client.timeOff.updateRequestStatus({
963
+ requestId,
964
+ status: opts.status,
965
+ note
966
+ });
967
+ output(result ? stripNullish(result) : { updated: true, requestId, status: opts.status });
968
+ }
969
+ );
813
970
  }
814
971
 
815
972
  // src/commands/timeoff/whos-out.ts
@@ -831,7 +988,7 @@ function registerTimeoffCommands(program) {
831
988
  const timeoff = program.command("timeoff").description("Time off operations");
832
989
  examples(timeoff, [
833
990
  "types --requestable",
834
- "create 504 --start-date 2026-04-01 --end-date 2026-04-01 --type-id 83 --amount 1",
991
+ "create 504 --start-date 2026-04-01 --end-date 2026-04-01 --type-id 83",
835
992
  ["requests --status requested --start-date 2026-01-01 --end-date 2026-12-31", "pending requests in date range"],
836
993
  "balance 504",
837
994
  "whos-out",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bamboohr-cli",
3
- "version": "1.0.19",
3
+ "version": "1.0.20-gc408819.2",
4
4
  "publish": true,
5
5
  "type": "module",
6
6
  "main": "dist/index.js",