@mauricode/token-derby 2.7.0 → 2.8.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.js +180 -6
- package/dist/bin.js.map +1 -1
- package/package.json +1 -1
package/dist/bin.js
CHANGED
|
@@ -190,6 +190,35 @@ var HATS = [
|
|
|
190
190
|
{ id: "aurora_helm", name: "Aurora Helm", rarity: "legendary", width: 11, anchor_x: 23, rows: ["...........", "...........", "...........", "...........", "...QQQQQ...", "...QQQQQ...", "..AAAAAAA..", "..AAAAAAA..", "..AQAAAQA..", "..AQAAAQA.."], colors: { A: "#00CED1", Q: "#00FF7F" }, animation: { type: "cycle", frames: ["#0000FF", "#0066FF", "#00BFFF", "#00CED1", "#00FF7F", "#7CFC00", "#00FF7F", "#00CED1"], fps: 4 } }
|
|
191
191
|
];
|
|
192
192
|
|
|
193
|
+
// ../shared/dist/schedule.js
|
|
194
|
+
var ORDER = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"];
|
|
195
|
+
function parseWeekdays(spec) {
|
|
196
|
+
const tokens = spec.toLowerCase().split(",").map((s) => s.trim()).filter(Boolean);
|
|
197
|
+
if (tokens.length === 0)
|
|
198
|
+
return null;
|
|
199
|
+
const set = /* @__PURE__ */ new Set();
|
|
200
|
+
for (const tok of tokens) {
|
|
201
|
+
if (tok.includes("-")) {
|
|
202
|
+
const parts = tok.split("-");
|
|
203
|
+
if (parts.length !== 2)
|
|
204
|
+
return null;
|
|
205
|
+
const [a, b] = parts;
|
|
206
|
+
const ai = ORDER.indexOf(a);
|
|
207
|
+
const bi = ORDER.indexOf(b);
|
|
208
|
+
if (ai < 0 || bi < 0 || ai > bi)
|
|
209
|
+
return null;
|
|
210
|
+
for (let i = ai; i <= bi; i++)
|
|
211
|
+
set.add(i + 1);
|
|
212
|
+
} else {
|
|
213
|
+
const i = ORDER.indexOf(tok);
|
|
214
|
+
if (i < 0)
|
|
215
|
+
return null;
|
|
216
|
+
set.add(i + 1);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return [...set].sort((x, y) => x - y);
|
|
220
|
+
}
|
|
221
|
+
|
|
193
222
|
// src/ui/HorseSprite.tsx
|
|
194
223
|
import { Box, Text } from "ink";
|
|
195
224
|
|
|
@@ -695,8 +724,8 @@ var HEARTBEAT_RETRY_DELAYS_MS = [1e3, 2e3, 4e3, 8e3, 15e3];
|
|
|
695
724
|
// src/version.ts
|
|
696
725
|
import { createRequire } from "module";
|
|
697
726
|
function readVersion() {
|
|
698
|
-
if ("2.
|
|
699
|
-
return "2.
|
|
727
|
+
if ("2.8.0".length > 0) {
|
|
728
|
+
return "2.8.0";
|
|
700
729
|
}
|
|
701
730
|
try {
|
|
702
731
|
const req = createRequire(import.meta.url);
|
|
@@ -910,6 +939,30 @@ function deleteOrgWebhook(orgName) {
|
|
|
910
939
|
void 0
|
|
911
940
|
);
|
|
912
941
|
}
|
|
942
|
+
function setOrgSchedule(orgName, body) {
|
|
943
|
+
return request(
|
|
944
|
+
"PUT",
|
|
945
|
+
`/organisations/${encodeURIComponent(orgName)}/schedule`,
|
|
946
|
+
body,
|
|
947
|
+
void 0
|
|
948
|
+
);
|
|
949
|
+
}
|
|
950
|
+
function getOrgSchedule(orgName) {
|
|
951
|
+
return request(
|
|
952
|
+
"GET",
|
|
953
|
+
`/organisations/${encodeURIComponent(orgName)}/schedule`,
|
|
954
|
+
void 0,
|
|
955
|
+
void 0
|
|
956
|
+
);
|
|
957
|
+
}
|
|
958
|
+
function clearOrgSchedule(orgName) {
|
|
959
|
+
return request(
|
|
960
|
+
"DELETE",
|
|
961
|
+
`/organisations/${encodeURIComponent(orgName)}/schedule`,
|
|
962
|
+
void 0,
|
|
963
|
+
void 0
|
|
964
|
+
);
|
|
965
|
+
}
|
|
913
966
|
function rollHat(stableHorseId) {
|
|
914
967
|
return request("POST", `/jockey/me/horses/${encodeURIComponent(stableHorseId)}/roll`, void 0, void 0);
|
|
915
968
|
}
|
|
@@ -2620,6 +2673,111 @@ async function orgWebhookClearCommand(orgName) {
|
|
|
2620
2673
|
}
|
|
2621
2674
|
}
|
|
2622
2675
|
|
|
2676
|
+
// src/commands/org-schedule-set.ts
|
|
2677
|
+
function flag(args, name) {
|
|
2678
|
+
for (let i = 0; i < args.length; i++) {
|
|
2679
|
+
if (args[i] === name) return args[i + 1];
|
|
2680
|
+
const eq = `${name}=`;
|
|
2681
|
+
if (args[i]?.startsWith(eq)) return args[i].slice(eq.length);
|
|
2682
|
+
}
|
|
2683
|
+
return void 0;
|
|
2684
|
+
}
|
|
2685
|
+
var USAGE = 'Usage: token-derby organisation schedule set <org-name> --days mon-fri --start 09:00 --end 17:30 --tz Europe/London [--name "Daily"] [--max 30] [--counts-input]';
|
|
2686
|
+
async function orgScheduleSetCommand(orgName, rest) {
|
|
2687
|
+
if (!orgName) {
|
|
2688
|
+
console.error(USAGE);
|
|
2689
|
+
return 2;
|
|
2690
|
+
}
|
|
2691
|
+
const daysSpec = flag(rest, "--days");
|
|
2692
|
+
const start = flag(rest, "--start");
|
|
2693
|
+
const end = flag(rest, "--end");
|
|
2694
|
+
const tz = flag(rest, "--tz");
|
|
2695
|
+
const name = flag(rest, "--name");
|
|
2696
|
+
const maxStr = flag(rest, "--max");
|
|
2697
|
+
const counts_input = rest.includes("--counts-input");
|
|
2698
|
+
if (!daysSpec || !start || !end || !tz) {
|
|
2699
|
+
console.error("Required flags: --days, --start, --end, --tz");
|
|
2700
|
+
console.error(USAGE);
|
|
2701
|
+
return 2;
|
|
2702
|
+
}
|
|
2703
|
+
const weekdays = parseWeekdays(daysSpec);
|
|
2704
|
+
if (!weekdays) {
|
|
2705
|
+
console.error('Invalid --days. Use day names like "mon-fri" or "mon,wed,fri".');
|
|
2706
|
+
return 2;
|
|
2707
|
+
}
|
|
2708
|
+
let max_participants;
|
|
2709
|
+
if (maxStr !== void 0) {
|
|
2710
|
+
max_participants = Number(maxStr);
|
|
2711
|
+
if (!Number.isInteger(max_participants) || max_participants < 1) {
|
|
2712
|
+
console.error("--max must be a positive integer");
|
|
2713
|
+
return 2;
|
|
2714
|
+
}
|
|
2715
|
+
}
|
|
2716
|
+
try {
|
|
2717
|
+
const resp = await setOrgSchedule(orgName, {
|
|
2718
|
+
weekdays,
|
|
2719
|
+
start_local: start,
|
|
2720
|
+
end_local: end,
|
|
2721
|
+
tz,
|
|
2722
|
+
...name ? { race_name: name } : {},
|
|
2723
|
+
...max_participants !== void 0 ? { max_participants } : {},
|
|
2724
|
+
...counts_input ? { counts_input: true } : {}
|
|
2725
|
+
});
|
|
2726
|
+
const s = resp.schedule;
|
|
2727
|
+
console.log(`Schedule set for ${orgName}: days [${s.weekdays.join(",")}] ${s.start_local}\u2013${s.end_local} ${s.tz}`);
|
|
2728
|
+
return 0;
|
|
2729
|
+
} catch (e) {
|
|
2730
|
+
if (e instanceof ApiError) {
|
|
2731
|
+
console.error(`Error: ${e.code} ${e.message}`);
|
|
2732
|
+
return 1;
|
|
2733
|
+
}
|
|
2734
|
+
throw e;
|
|
2735
|
+
}
|
|
2736
|
+
}
|
|
2737
|
+
|
|
2738
|
+
// src/commands/org-schedule-get.ts
|
|
2739
|
+
async function orgScheduleGetCommand(orgName) {
|
|
2740
|
+
if (!orgName) {
|
|
2741
|
+
console.error("Usage: token-derby organisation schedule get <org-name>");
|
|
2742
|
+
return 2;
|
|
2743
|
+
}
|
|
2744
|
+
try {
|
|
2745
|
+
const resp = await getOrgSchedule(orgName);
|
|
2746
|
+
if (resp.schedule) {
|
|
2747
|
+
const s = resp.schedule;
|
|
2748
|
+
console.log(`Schedule for ${orgName}: days [${s.weekdays.join(",")}] ${s.start_local}\u2013${s.end_local} ${s.tz}`);
|
|
2749
|
+
} else {
|
|
2750
|
+
console.log(`No schedule configured for ${orgName}.`);
|
|
2751
|
+
}
|
|
2752
|
+
return 0;
|
|
2753
|
+
} catch (e) {
|
|
2754
|
+
if (e instanceof ApiError) {
|
|
2755
|
+
console.error(`Error: ${e.code} ${e.message}`);
|
|
2756
|
+
return 1;
|
|
2757
|
+
}
|
|
2758
|
+
throw e;
|
|
2759
|
+
}
|
|
2760
|
+
}
|
|
2761
|
+
|
|
2762
|
+
// src/commands/org-schedule-clear.ts
|
|
2763
|
+
async function orgScheduleClearCommand(orgName) {
|
|
2764
|
+
if (!orgName) {
|
|
2765
|
+
console.error("Usage: token-derby organisation schedule clear <org-name>");
|
|
2766
|
+
return 2;
|
|
2767
|
+
}
|
|
2768
|
+
try {
|
|
2769
|
+
await clearOrgSchedule(orgName);
|
|
2770
|
+
console.log(`Schedule removed for ${orgName}.`);
|
|
2771
|
+
return 0;
|
|
2772
|
+
} catch (e) {
|
|
2773
|
+
if (e instanceof ApiError) {
|
|
2774
|
+
console.error(`Error: ${e.code} ${e.message}`);
|
|
2775
|
+
return 1;
|
|
2776
|
+
}
|
|
2777
|
+
throw e;
|
|
2778
|
+
}
|
|
2779
|
+
}
|
|
2780
|
+
|
|
2623
2781
|
// src/bin.ts
|
|
2624
2782
|
var HELP = `token-derby v${CLI_VERSION}
|
|
2625
2783
|
|
|
@@ -2651,6 +2809,13 @@ Organisations:
|
|
|
2651
2809
|
Show the org's configured webhook URL (or "no webhook").
|
|
2652
2810
|
token-derby organisation webhook clear <name>
|
|
2653
2811
|
Remove the webhook for this org.
|
|
2812
|
+
token-derby organisation schedule set <name> --days mon-fri --start 09:00 --end 17:30 --tz Europe/London
|
|
2813
|
+
Configure a repeating race schedule. Races auto-start
|
|
2814
|
+
at the daily start time. Only the org creator can run this.
|
|
2815
|
+
token-derby organisation schedule get <name>
|
|
2816
|
+
Show the org's configured schedule (or "no schedule").
|
|
2817
|
+
token-derby organisation schedule clear <name>
|
|
2818
|
+
Remove the repeating schedule for this org.
|
|
2654
2819
|
|
|
2655
2820
|
Races:
|
|
2656
2821
|
token-derby create [--organisation <name>]
|
|
@@ -2714,8 +2879,17 @@ async function main() {
|
|
|
2714
2879
|
console.error("Try: organisation webhook set <name> <url> | organisation webhook get <name> | organisation webhook clear <name>");
|
|
2715
2880
|
return 2;
|
|
2716
2881
|
}
|
|
2882
|
+
if (sub === "schedule") {
|
|
2883
|
+
const action = argv[2];
|
|
2884
|
+
if (action === "set") return orgScheduleSetCommand(argv[3], argv.slice(4));
|
|
2885
|
+
if (action === "get") return orgScheduleGetCommand(argv[3]);
|
|
2886
|
+
if (action === "clear") return orgScheduleClearCommand(argv[3]);
|
|
2887
|
+
console.error(`Unknown schedule action: ${action ?? "(none)"}`);
|
|
2888
|
+
console.error("Try: organisation schedule set <name> ... | organisation schedule get <name> | organisation schedule clear <name>");
|
|
2889
|
+
return 2;
|
|
2890
|
+
}
|
|
2717
2891
|
console.error(`Unknown organisation subcommand: ${sub ?? "(none)"}`);
|
|
2718
|
-
console.error("Try: organisation create | organisation join <token> | organisation info <name> | organisation list | organisation webhook <set|get|clear> ...");
|
|
2892
|
+
console.error("Try: organisation create | organisation join <token> | organisation info <name> | organisation list | organisation webhook <set|get|clear> ... | organisation schedule <set|get|clear> ...");
|
|
2719
2893
|
return 2;
|
|
2720
2894
|
}
|
|
2721
2895
|
if (cmd === "create") {
|
|
@@ -2729,10 +2903,10 @@ async function main() {
|
|
|
2729
2903
|
console.error(HELP);
|
|
2730
2904
|
return 2;
|
|
2731
2905
|
}
|
|
2732
|
-
function parseFlag(args,
|
|
2906
|
+
function parseFlag(args, flag2) {
|
|
2733
2907
|
for (let i = 0; i < args.length; i++) {
|
|
2734
|
-
if (args[i] ===
|
|
2735
|
-
const eq = `${
|
|
2908
|
+
if (args[i] === flag2) return args[i + 1];
|
|
2909
|
+
const eq = `${flag2}=`;
|
|
2736
2910
|
if (args[i]?.startsWith(eq)) return args[i].slice(eq.length);
|
|
2737
2911
|
}
|
|
2738
2912
|
return void 0;
|