@hasna/events 0.1.4 → 0.1.5
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/cli/index.d.ts +5 -1
- package/dist/cli/index.js +52 -41
- package/package.json +5 -1
package/dist/cli/index.d.ts
CHANGED
package/dist/cli/index.js
CHANGED
|
@@ -631,29 +631,34 @@ function output(parsed, value, human) {
|
|
|
631
631
|
}
|
|
632
632
|
human();
|
|
633
633
|
}
|
|
634
|
-
function
|
|
635
|
-
|
|
634
|
+
function commandName(options) {
|
|
635
|
+
return options.programName ?? "events";
|
|
636
|
+
}
|
|
637
|
+
function printHelp(options = {}) {
|
|
638
|
+
const name = commandName(options);
|
|
639
|
+
console.log(`${name} ${version()}
|
|
636
640
|
|
|
637
641
|
Usage:
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
642
|
+
${name} [--dir <path>] [--json] webhooks add <url|command> [options]
|
|
643
|
+
${name} [--dir <path>] [--json] webhooks list
|
|
644
|
+
${name} [--dir <path>] [--json] webhooks remove <id>
|
|
645
|
+
${name} [--dir <path>] [--json] webhooks test <id>
|
|
646
|
+
${name} [--dir <path>] [--json] events emit <type>${options.source ? "" : " --source <source>"} [options]
|
|
647
|
+
${name} [--dir <path>] [--json] events list [--limit <n>]
|
|
648
|
+
${name} [--dir <path>] [--json] events replay [--id <event-id>] [--dry-run]
|
|
645
649
|
|
|
646
650
|
Environment:
|
|
647
651
|
HASNA_EVENTS_DIR or HASNA_EVENTS_HOME overrides the default ${getEventsDataDir()}`);
|
|
648
652
|
}
|
|
649
|
-
function printWebhooksHelp() {
|
|
650
|
-
|
|
653
|
+
function printWebhooksHelp(options = {}) {
|
|
654
|
+
const name = commandName(options);
|
|
655
|
+
console.log(`${name} webhooks
|
|
651
656
|
|
|
652
657
|
Usage:
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
658
|
+
${name} [--dir <path>] [--json] webhooks add <url|command> [options]
|
|
659
|
+
${name} [--dir <path>] [--json] webhooks list
|
|
660
|
+
${name} [--dir <path>] [--json] webhooks remove <id>
|
|
661
|
+
${name} [--dir <path>] [--json] webhooks test <id>
|
|
657
662
|
|
|
658
663
|
Options:
|
|
659
664
|
--id <id> Channel id for add
|
|
@@ -667,16 +672,17 @@ Options:
|
|
|
667
672
|
--redact <path> Redaction path, repeatable
|
|
668
673
|
--no-deliver Available on events emit`);
|
|
669
674
|
}
|
|
670
|
-
function printEventsHelp() {
|
|
671
|
-
|
|
675
|
+
function printEventsHelp(options = {}) {
|
|
676
|
+
const name = commandName(options);
|
|
677
|
+
console.log(`${name} events
|
|
672
678
|
|
|
673
679
|
Usage:
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
680
|
+
${name} [--dir <path>] [--json] events emit <type>${options.source ? "" : " --source <source>"} [options]
|
|
681
|
+
${name} [--dir <path>] [--json] events list [--limit <n>]
|
|
682
|
+
${name} [--dir <path>] [--json] events replay [--id <event-id>] [--dry-run]
|
|
677
683
|
|
|
678
684
|
Options:
|
|
679
|
-
--source <source> Event source
|
|
685
|
+
--source <source> Event source${options.source ? ` (default: ${options.source})` : ""}
|
|
680
686
|
--subject <subject> Event subject
|
|
681
687
|
--severity <severity> Event severity
|
|
682
688
|
--message <message> Human-readable event message
|
|
@@ -686,11 +692,11 @@ Options:
|
|
|
686
692
|
--no-deliver Record without delivering webhooks
|
|
687
693
|
--dry-run Preview replay matches without delivery`);
|
|
688
694
|
}
|
|
689
|
-
async function
|
|
695
|
+
async function runEventsCli(argv = process.argv.slice(2), options = {}) {
|
|
690
696
|
const parsed = parseGlobalArgs(argv);
|
|
691
697
|
const [group, command, ...tail] = parsed.rest;
|
|
692
698
|
if (!group || group === "--help" || group === "-h") {
|
|
693
|
-
printHelp();
|
|
699
|
+
printHelp(options);
|
|
694
700
|
return;
|
|
695
701
|
}
|
|
696
702
|
if (group === "--version" || group === "-v") {
|
|
@@ -701,23 +707,23 @@ async function main(argv = process.argv.slice(2)) {
|
|
|
701
707
|
const client = new EventsClient({ store });
|
|
702
708
|
if (group === "webhooks") {
|
|
703
709
|
if (!command || command === "--help" || command === "-h") {
|
|
704
|
-
printWebhooksHelp();
|
|
710
|
+
printWebhooksHelp(options);
|
|
705
711
|
return;
|
|
706
712
|
}
|
|
707
|
-
await handleWebhooks(client, command, tail, parsed);
|
|
713
|
+
await handleWebhooks(client, command, tail, parsed, options);
|
|
708
714
|
return;
|
|
709
715
|
}
|
|
710
716
|
if (group === "events") {
|
|
711
717
|
if (!command || command === "--help" || command === "-h") {
|
|
712
|
-
printEventsHelp();
|
|
718
|
+
printEventsHelp(options);
|
|
713
719
|
return;
|
|
714
720
|
}
|
|
715
|
-
await handleEvents(client, command, tail, parsed);
|
|
721
|
+
await handleEvents(client, command, tail, parsed, options);
|
|
716
722
|
return;
|
|
717
723
|
}
|
|
718
724
|
throw new Error(`Unknown command group: ${group}`);
|
|
719
725
|
}
|
|
720
|
-
async function handleWebhooks(client, command, tail, parsed) {
|
|
726
|
+
async function handleWebhooks(client, command, tail, parsed, options) {
|
|
721
727
|
if (command === "add") {
|
|
722
728
|
const args = [...tail];
|
|
723
729
|
const transport = takeOption(args, "--transport") ?? "webhook";
|
|
@@ -785,7 +791,7 @@ async function handleWebhooks(client, command, tail, parsed) {
|
|
|
785
791
|
if (!id)
|
|
786
792
|
throw new Error("webhooks test requires a channel id");
|
|
787
793
|
const result = await client.testChannel(id, {
|
|
788
|
-
source: takeOption(args, "--source") ?? "hasna.events",
|
|
794
|
+
source: takeOption(args, "--source") ?? options.source ?? "hasna.events",
|
|
789
795
|
type: takeOption(args, "--type") ?? "events.test",
|
|
790
796
|
subject: takeOption(args, "--subject") ?? id,
|
|
791
797
|
data: parseJsonOption(takeOption(args, "--data"), { test: true })
|
|
@@ -795,13 +801,13 @@ async function handleWebhooks(client, command, tail, parsed) {
|
|
|
795
801
|
}
|
|
796
802
|
throw new Error(`Unknown webhooks command: ${command ?? ""}`);
|
|
797
803
|
}
|
|
798
|
-
async function handleEvents(client, command, tail, parsed) {
|
|
804
|
+
async function handleEvents(client, command, tail, parsed, options) {
|
|
799
805
|
if (command === "emit") {
|
|
800
806
|
const args = [...tail];
|
|
801
807
|
const type = args.shift();
|
|
802
808
|
if (!type)
|
|
803
809
|
throw new Error("events emit requires an event type");
|
|
804
|
-
const source = takeOption(args, "--source");
|
|
810
|
+
const source = takeOption(args, "--source") ?? options.source;
|
|
805
811
|
if (!source)
|
|
806
812
|
throw new Error("events emit requires --source");
|
|
807
813
|
const noDeliver = takeFlag(args, "--no-deliver");
|
|
@@ -870,13 +876,18 @@ function severityOption(value) {
|
|
|
870
876
|
throw new Error(`Invalid severity: ${value}`);
|
|
871
877
|
return value;
|
|
872
878
|
}
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
879
|
+
if (import.meta.main) {
|
|
880
|
+
runEventsCli().catch((error) => {
|
|
881
|
+
const parsed = parseGlobalArgs(process.argv.slice(2));
|
|
882
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
883
|
+
if (parsed.json) {
|
|
884
|
+
console.log(JSON.stringify({ error: message }, null, 2));
|
|
885
|
+
} else {
|
|
886
|
+
console.error(message);
|
|
887
|
+
}
|
|
888
|
+
process.exit(1);
|
|
889
|
+
});
|
|
890
|
+
}
|
|
891
|
+
export {
|
|
892
|
+
runEventsCli
|
|
893
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hasna/events",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "Shared event envelopes, local subscriptions, and webhook delivery for Hasna open-source apps",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -33,6 +33,10 @@
|
|
|
33
33
|
"./commander": {
|
|
34
34
|
"types": "./dist/commander.d.ts",
|
|
35
35
|
"import": "./dist/commander.js"
|
|
36
|
+
},
|
|
37
|
+
"./cli": {
|
|
38
|
+
"types": "./dist/cli/index.d.ts",
|
|
39
|
+
"import": "./dist/cli/index.js"
|
|
36
40
|
}
|
|
37
41
|
},
|
|
38
42
|
"files": [
|