@andocorp/cli 0.3.0 → 0.3.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.
- package/README.md +30 -0
- package/dist/api-command.js +26 -1
- package/dist/help.js +15 -1
- package/dist/index.js +5 -0
- package/dist/watch-commands.js +6 -5
- package/dist/webhook-commands.js +360 -0
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -97,6 +97,36 @@ be a public path or an operation ID from `ando api ls`; query and header names
|
|
|
97
97
|
are validated against the generated public API metadata. For operation ID
|
|
98
98
|
targets, supply required path parameters as `name=value`.
|
|
99
99
|
|
|
100
|
+
Webhook endpoint and delivery commands cover the same SDK webhook management
|
|
101
|
+
surface with human-readable output by default and `--json` for scripts.
|
|
102
|
+
|
|
103
|
+
```sh
|
|
104
|
+
ando webhooks endpoints list
|
|
105
|
+
ando webhooks endpoints create \
|
|
106
|
+
--url https://example.com/ando/webhooks \
|
|
107
|
+
--events webhook.test,message.created \
|
|
108
|
+
--name "Development receiver" \
|
|
109
|
+
--include-direct-messages
|
|
110
|
+
ando webhooks endpoints get <endpoint-id> --json
|
|
111
|
+
ando webhooks endpoints update <endpoint-id> \
|
|
112
|
+
--events webhook.test,message.created \
|
|
113
|
+
--exclude-direct-messages
|
|
114
|
+
ando webhooks endpoints disable <endpoint-id>
|
|
115
|
+
ando webhooks endpoints rotate-secret <endpoint-id> --previous-secret-ttl 3600
|
|
116
|
+
ando webhooks endpoints test <endpoint-id> --watch-delivery
|
|
117
|
+
ando webhooks deliveries list --endpoint <endpoint-id> --status failed
|
|
118
|
+
ando webhooks deliveries replay <delivery-id>
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Endpoint creation and secret rotation print one-time signing secrets in the
|
|
122
|
+
plain output. Store the secret before clearing the terminal. Webhook endpoints
|
|
123
|
+
act as the creating member/API member; direct messages are excluded unless
|
|
124
|
+
`--include-direct-messages` is set. For local receiver development, expose the
|
|
125
|
+
local server with a public HTTPS tunnel, create or update the endpoint URL, then
|
|
126
|
+
run `ando webhooks endpoints test <endpoint-id>` to send a `webhook.test`
|
|
127
|
+
event. The CLI does not include a Stripe-style `listen --forward-to` relay
|
|
128
|
+
command unless Ando adds a backend relay for local forwarding.
|
|
129
|
+
|
|
100
130
|
```sh
|
|
101
131
|
ando messages --channel engineering --limit 10
|
|
102
132
|
ando messages -c engineering -m 10
|
package/dist/api-command.js
CHANGED
|
@@ -58,6 +58,27 @@ function requestBodyFromInputs(params) {
|
|
|
58
58
|
}
|
|
59
59
|
return params.dataBody !== undefined ? params.dataBody : params.assignmentBody;
|
|
60
60
|
}
|
|
61
|
+
function inferRequestMethod(params) {
|
|
62
|
+
if (params.requestedMethod != null) {
|
|
63
|
+
return params.requestedMethod;
|
|
64
|
+
}
|
|
65
|
+
const methods = [...new Set(params.matches.map((match) => match.operation.method))];
|
|
66
|
+
if (methods.length === 1) {
|
|
67
|
+
return methods[0];
|
|
68
|
+
}
|
|
69
|
+
if (params.body !== undefined) {
|
|
70
|
+
const bodyMethods = [
|
|
71
|
+
...new Set(params.matches
|
|
72
|
+
.filter((match) => match.operation.requestBodySchema != null)
|
|
73
|
+
.map((match) => match.operation.method)),
|
|
74
|
+
];
|
|
75
|
+
if (bodyMethods.length === 1) {
|
|
76
|
+
return bodyMethods[0];
|
|
77
|
+
}
|
|
78
|
+
return bodyMethods.includes("POST") ? "POST" : (bodyMethods[0] ?? "POST");
|
|
79
|
+
}
|
|
80
|
+
return methods.includes("GET") ? "GET" : "POST";
|
|
81
|
+
}
|
|
61
82
|
function rejectMixedBodySourcesBeforeRead(params) {
|
|
62
83
|
if (params.inlineBodyFieldCount > 0 && hasFlag(params.parsedArgs, "data", "d")) {
|
|
63
84
|
throw new Error("Use either --data or inline body fields, not both.");
|
|
@@ -108,7 +129,11 @@ async function prepareApiRequest(params) {
|
|
|
108
129
|
? buildBodyFromAssignments(pathParameterInputs.bodyAssignments)
|
|
109
130
|
: undefined;
|
|
110
131
|
const body = requestBodyFromInputs({ assignmentBody, dataBody });
|
|
111
|
-
const method =
|
|
132
|
+
const method = inferRequestMethod({
|
|
133
|
+
body,
|
|
134
|
+
matches: params.matches,
|
|
135
|
+
requestedMethod: params.requestedMethod,
|
|
136
|
+
});
|
|
112
137
|
const selectedMatch = selectOperation(params.rawPath, params.matches, method);
|
|
113
138
|
const { match } = applyPathParameterAssignments({
|
|
114
139
|
bodyAssignments: inlineInputs.bodyAssignments,
|
package/dist/help.js
CHANGED
|
@@ -29,7 +29,17 @@ Agent-first commands:
|
|
|
29
29
|
ando get transcript <call-id> [--limit <n>] [--cursor <cursor>] [--json]
|
|
30
30
|
ando thread <thread-root-message-id> [--limit <n>] [--after <cursor>] [--json]
|
|
31
31
|
ando thread -m <message-id> [--json]
|
|
32
|
-
ando watch messages [--delivery mentions] [--limit|-n <n>] [--timeout <ms>] [--json]
|
|
32
|
+
ando watch messages [--delivery messages|mentions] [--limit|-n <n>] [--timeout <ms>] [--json]
|
|
33
|
+
ando webhooks endpoints list [--json]
|
|
34
|
+
ando webhooks endpoints create --url <url> --events <csv> [--name <name>] [--include-direct-messages] [--json]
|
|
35
|
+
ando webhooks endpoints get <endpoint-id> [--json]
|
|
36
|
+
ando webhooks endpoints update <endpoint-id> [--url <url>] [--events <csv>] [--name <name>] [--include-direct-messages|--exclude-direct-messages] [--json]
|
|
37
|
+
ando webhooks endpoints disable <endpoint-id> [--json]
|
|
38
|
+
ando webhooks endpoints rotate-secret <endpoint-id> [--previous-secret-ttl <seconds>] [--json]
|
|
39
|
+
ando webhooks endpoints test <endpoint-id> [--json]
|
|
40
|
+
ando webhooks endpoints test <endpoint-id> --watch-delivery [--timeout <ms>]
|
|
41
|
+
ando webhooks deliveries list [--endpoint <id>] [--event <id>] [--status <status>] [--limit|-n <n>] [--json]
|
|
42
|
+
ando webhooks deliveries replay <delivery-id> [--json]
|
|
33
43
|
|
|
34
44
|
Authentication:
|
|
35
45
|
login opens a browser authorization page, shows a verification code, and stores
|
|
@@ -66,5 +76,9 @@ Examples:
|
|
|
66
76
|
ando get message <message-id>
|
|
67
77
|
ando thread <thread-root-message-id> --limit 50
|
|
68
78
|
ando watch messages --limit 1 --json
|
|
79
|
+
ando webhooks endpoints create --url https://example.com/ando/webhooks --events webhook.test,message.created --include-direct-messages
|
|
80
|
+
ando webhooks endpoints rotate-secret <endpoint-id> --previous-secret-ttl 3600
|
|
81
|
+
ando webhooks endpoints test <endpoint-id> --watch-delivery
|
|
82
|
+
ando webhooks deliveries list --endpoint <endpoint-id> --status failed
|
|
69
83
|
`.trim();
|
|
70
84
|
}
|
package/dist/index.js
CHANGED
|
@@ -9,6 +9,7 @@ import { runLogin } from "./commands.js";
|
|
|
9
9
|
import { printHelp } from "./output.js";
|
|
10
10
|
import { ensureConfig, getConfiguredApiHost } from "./session.js";
|
|
11
11
|
import { DEFAULT_CLI_REQUEST_TIMEOUT_MS } from "./timeouts.js";
|
|
12
|
+
import { runWebhookCommand } from "./webhook-commands.js";
|
|
12
13
|
import { runWatchCommand } from "./watch-commands.js";
|
|
13
14
|
const cliCommandHandlers = new Map([
|
|
14
15
|
[
|
|
@@ -27,6 +28,10 @@ const apiCommandHandlers = new Map([
|
|
|
27
28
|
async ({ apiClient, parsedArgs }) => runSearchCommand({ apiClient, parsedArgs }),
|
|
28
29
|
],
|
|
29
30
|
["thread", runAgentThreadCommand],
|
|
31
|
+
[
|
|
32
|
+
"webhooks",
|
|
33
|
+
async ({ apiClient, parsedArgs }) => runWebhookCommand({ apiClient, parsedArgs }),
|
|
34
|
+
],
|
|
30
35
|
]);
|
|
31
36
|
function createApiClient(config, parsedArgs) {
|
|
32
37
|
return new AndoClient({
|
package/dist/watch-commands.js
CHANGED
|
@@ -15,12 +15,12 @@ function getWatchDelivery(parsedArgs) {
|
|
|
15
15
|
const delivery = getStringFlag(parsedArgs, "delivery");
|
|
16
16
|
if (delivery == null) {
|
|
17
17
|
if (hasFlag(parsedArgs, "all")) {
|
|
18
|
-
throw new Error('Public realtime currently supports --delivery "mentions"
|
|
18
|
+
throw new Error('Public realtime currently supports --delivery "messages" or "mentions".');
|
|
19
19
|
}
|
|
20
|
-
return "
|
|
20
|
+
return "messages";
|
|
21
21
|
}
|
|
22
|
-
if (delivery !== "mentions") {
|
|
23
|
-
throw new Error('Unknown --delivery value. Expected "mentions".');
|
|
22
|
+
if (delivery !== "messages" && delivery !== "mentions") {
|
|
23
|
+
throw new Error('Unknown --delivery value. Expected "messages" or "mentions".');
|
|
24
24
|
}
|
|
25
25
|
return delivery;
|
|
26
26
|
}
|
|
@@ -54,6 +54,7 @@ function writeWatchJsonEvent(event) {
|
|
|
54
54
|
createdAt: event.message.created_at,
|
|
55
55
|
threadRootId: event.message.thread_root_id ?? null,
|
|
56
56
|
repliesCount: event.message.replies_count,
|
|
57
|
+
wasMentioned: event.wasMentioned ?? false,
|
|
57
58
|
context: event.context,
|
|
58
59
|
})}\n`);
|
|
59
60
|
}
|
|
@@ -101,7 +102,7 @@ export async function runWatchCommand({ apiClient, parsedArgs, isInteractive = B
|
|
|
101
102
|
},
|
|
102
103
|
});
|
|
103
104
|
if (isInteractive) {
|
|
104
|
-
process.stderr.write("Watching
|
|
105
|
+
process.stderr.write("Watching messages via realtime. Press Ctrl-C to stop.\n");
|
|
105
106
|
}
|
|
106
107
|
await subscription.done();
|
|
107
108
|
}
|
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
import { getStringFlag, hasFlag } from "./args.js";
|
|
2
|
+
import { printJson } from "./output.js";
|
|
3
|
+
const WEBHOOK_EVENT_KINDS = [
|
|
4
|
+
"message.created",
|
|
5
|
+
"message.updated",
|
|
6
|
+
"conversation.membership.created",
|
|
7
|
+
"conversation.archived",
|
|
8
|
+
"conversation.unarchived",
|
|
9
|
+
"call.started",
|
|
10
|
+
"call.ended",
|
|
11
|
+
"call.updated",
|
|
12
|
+
"call.transcript.updated",
|
|
13
|
+
"webhook.test",
|
|
14
|
+
];
|
|
15
|
+
const WEBHOOK_DELIVERY_STATUSES = [
|
|
16
|
+
"pending",
|
|
17
|
+
"scheduled",
|
|
18
|
+
"in_flight",
|
|
19
|
+
"succeeded",
|
|
20
|
+
"retrying",
|
|
21
|
+
"failed",
|
|
22
|
+
"skipped",
|
|
23
|
+
];
|
|
24
|
+
const TERMINAL_DELIVERY_STATUSES = new Set([
|
|
25
|
+
"succeeded",
|
|
26
|
+
"failed",
|
|
27
|
+
"skipped",
|
|
28
|
+
]);
|
|
29
|
+
function isWebhookEventKind(value) {
|
|
30
|
+
return WEBHOOK_EVENT_KINDS.includes(value);
|
|
31
|
+
}
|
|
32
|
+
function isWebhookDeliveryStatus(value) {
|
|
33
|
+
return WEBHOOK_DELIVERY_STATUSES.includes(value);
|
|
34
|
+
}
|
|
35
|
+
function requireStringFlag(parsedArgs, longName, shortName) {
|
|
36
|
+
const value = getStringFlag(parsedArgs, longName, shortName);
|
|
37
|
+
if (value == null || value.trim() === "") {
|
|
38
|
+
throw new Error(`webhooks endpoints requires --${longName} <value>.`);
|
|
39
|
+
}
|
|
40
|
+
return value.trim();
|
|
41
|
+
}
|
|
42
|
+
function parseWebhookEvents(value) {
|
|
43
|
+
const events = value
|
|
44
|
+
.split(",")
|
|
45
|
+
.map((event) => event.trim())
|
|
46
|
+
.filter((event) => event !== "");
|
|
47
|
+
if (events.length === 0) {
|
|
48
|
+
throw new Error("--events must include at least one event type.");
|
|
49
|
+
}
|
|
50
|
+
const parsedEvents = [];
|
|
51
|
+
for (const event of events) {
|
|
52
|
+
if (!isWebhookEventKind(event)) {
|
|
53
|
+
throw new Error(`Unknown webhook event "${event}". Expected one of ${WEBHOOK_EVENT_KINDS.join(", ")}.`);
|
|
54
|
+
}
|
|
55
|
+
parsedEvents.push(event);
|
|
56
|
+
}
|
|
57
|
+
return parsedEvents;
|
|
58
|
+
}
|
|
59
|
+
function getOptionalWebhookEvents(parsedArgs) {
|
|
60
|
+
const value = getStringFlag(parsedArgs, "events", "e");
|
|
61
|
+
return value == null ? undefined : parseWebhookEvents(value);
|
|
62
|
+
}
|
|
63
|
+
function getOptionalEndpointName(parsedArgs) {
|
|
64
|
+
return getStringFlag(parsedArgs, "name", "n");
|
|
65
|
+
}
|
|
66
|
+
function getOptionalDirectMessageDeliveryFlag(parsedArgs) {
|
|
67
|
+
const include = hasFlag(parsedArgs, "include-direct-messages");
|
|
68
|
+
const exclude = hasFlag(parsedArgs, "exclude-direct-messages");
|
|
69
|
+
if (include && exclude) {
|
|
70
|
+
throw new Error("Use only one of --include-direct-messages or --exclude-direct-messages.");
|
|
71
|
+
}
|
|
72
|
+
if (include)
|
|
73
|
+
return true;
|
|
74
|
+
if (exclude)
|
|
75
|
+
return false;
|
|
76
|
+
return undefined;
|
|
77
|
+
}
|
|
78
|
+
function getPositiveIntegerFlag(parsedArgs, longName) {
|
|
79
|
+
if (!hasFlag(parsedArgs, longName)) {
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
const value = getStringFlag(parsedArgs, longName);
|
|
83
|
+
if (value == null || value.trim() === "") {
|
|
84
|
+
throw new Error(`--${longName} must be a non-negative integer.`);
|
|
85
|
+
}
|
|
86
|
+
const parsed = Number.parseInt(value, 10);
|
|
87
|
+
if (!Number.isSafeInteger(parsed) || parsed < 0 || String(parsed) !== value.trim()) {
|
|
88
|
+
throw new Error(`--${longName} must be a non-negative integer.`);
|
|
89
|
+
}
|
|
90
|
+
return parsed;
|
|
91
|
+
}
|
|
92
|
+
function getPositiveLimitFlag(parsedArgs) {
|
|
93
|
+
if (!hasFlag(parsedArgs, "limit", "n")) {
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
96
|
+
const value = getStringFlag(parsedArgs, "limit", "n");
|
|
97
|
+
if (value == null || value.trim() === "") {
|
|
98
|
+
throw new Error("--limit must be a positive integer.");
|
|
99
|
+
}
|
|
100
|
+
const parsed = Number.parseInt(value, 10);
|
|
101
|
+
if (!Number.isSafeInteger(parsed) || parsed <= 0 || String(parsed) !== value.trim()) {
|
|
102
|
+
throw new Error("--limit must be a positive integer.");
|
|
103
|
+
}
|
|
104
|
+
return parsed;
|
|
105
|
+
}
|
|
106
|
+
function getOptionalStringFlagValue(parsedArgs, longName) {
|
|
107
|
+
if (!hasFlag(parsedArgs, longName)) {
|
|
108
|
+
return undefined;
|
|
109
|
+
}
|
|
110
|
+
const value = getStringFlag(parsedArgs, longName);
|
|
111
|
+
if (value == null || value.trim() === "") {
|
|
112
|
+
throw new Error(`--${longName} requires a value.`);
|
|
113
|
+
}
|
|
114
|
+
return value.trim();
|
|
115
|
+
}
|
|
116
|
+
function getDeliveryStatusFlag(parsedArgs) {
|
|
117
|
+
const value = getOptionalStringFlagValue(parsedArgs, "status");
|
|
118
|
+
if (value == null) {
|
|
119
|
+
return undefined;
|
|
120
|
+
}
|
|
121
|
+
if (!isWebhookDeliveryStatus(value)) {
|
|
122
|
+
throw new Error(`Unknown webhook delivery status "${value}". Expected one of ${WEBHOOK_DELIVERY_STATUSES.join(", ")}.`);
|
|
123
|
+
}
|
|
124
|
+
return value;
|
|
125
|
+
}
|
|
126
|
+
function sleep(ms) {
|
|
127
|
+
return new Promise((resolve) => {
|
|
128
|
+
setTimeout(resolve, ms);
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
function writeEndpointLine(endpoint) {
|
|
132
|
+
process.stdout.write(`${endpoint.id}\t${endpoint.status}\t${endpoint.url}\t${endpoint.enabled_events.join(",")}\t${endpoint.name ?? ""}\n`);
|
|
133
|
+
}
|
|
134
|
+
function writeEndpointSecret(endpoint) {
|
|
135
|
+
writeEndpointLine(endpoint);
|
|
136
|
+
process.stdout.write(`signing_secret\t${endpoint.signing_secret}\n`);
|
|
137
|
+
}
|
|
138
|
+
function writeDeliveryLine(delivery) {
|
|
139
|
+
process.stdout.write(`${delivery.id}\t${delivery.status}\t${delivery.event_type}\t${delivery.attempt_count}/${delivery.max_attempts}\t${delivery.last_http_status ?? ""}\t${delivery.last_error_code ?? ""}\t${delivery.next_attempt_at ?? ""}\n`);
|
|
140
|
+
}
|
|
141
|
+
async function listEndpoints(client, jsonFlag) {
|
|
142
|
+
const response = await client.webhooks.listEndpoints();
|
|
143
|
+
if (jsonFlag) {
|
|
144
|
+
printJson(response);
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
for (const endpoint of response.items) {
|
|
148
|
+
writeEndpointLine(endpoint);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
async function createEndpoint(client, parsedArgs, jsonFlag) {
|
|
152
|
+
const input = {
|
|
153
|
+
url: requireStringFlag(parsedArgs, "url", "u"),
|
|
154
|
+
enabledEvents: parseWebhookEvents(requireStringFlag(parsedArgs, "events", "e")),
|
|
155
|
+
};
|
|
156
|
+
const name = getOptionalEndpointName(parsedArgs);
|
|
157
|
+
if (name !== undefined) {
|
|
158
|
+
input.name = name;
|
|
159
|
+
}
|
|
160
|
+
const directMessageDeliveryEnabled = getOptionalDirectMessageDeliveryFlag(parsedArgs);
|
|
161
|
+
if (directMessageDeliveryEnabled !== undefined) {
|
|
162
|
+
input.deliveryScope = { directMessageDeliveryEnabled };
|
|
163
|
+
}
|
|
164
|
+
const response = await client.webhooks.createEndpoint(input);
|
|
165
|
+
if (jsonFlag) {
|
|
166
|
+
printJson(response);
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
writeEndpointSecret(response.data);
|
|
170
|
+
}
|
|
171
|
+
async function getEndpoint(client, endpointId, jsonFlag) {
|
|
172
|
+
const response = await client.webhooks.getEndpoint(endpointId);
|
|
173
|
+
if (jsonFlag) {
|
|
174
|
+
printJson(response);
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
writeEndpointLine(response.data);
|
|
178
|
+
}
|
|
179
|
+
async function updateEndpoint(client, endpointId, parsedArgs, jsonFlag) {
|
|
180
|
+
const input = {};
|
|
181
|
+
const url = getStringFlag(parsedArgs, "url", "u");
|
|
182
|
+
const events = getOptionalWebhookEvents(parsedArgs);
|
|
183
|
+
const name = getOptionalEndpointName(parsedArgs);
|
|
184
|
+
const directMessageDeliveryEnabled = getOptionalDirectMessageDeliveryFlag(parsedArgs);
|
|
185
|
+
if (url !== undefined) {
|
|
186
|
+
input.url = url;
|
|
187
|
+
}
|
|
188
|
+
if (events !== undefined) {
|
|
189
|
+
input.enabledEvents = events;
|
|
190
|
+
}
|
|
191
|
+
if (name !== undefined) {
|
|
192
|
+
input.name = name;
|
|
193
|
+
}
|
|
194
|
+
if (directMessageDeliveryEnabled !== undefined) {
|
|
195
|
+
input.deliveryScope = { directMessageDeliveryEnabled };
|
|
196
|
+
}
|
|
197
|
+
if (input.url === undefined &&
|
|
198
|
+
input.enabledEvents === undefined &&
|
|
199
|
+
input.name === undefined &&
|
|
200
|
+
input.deliveryScope === undefined) {
|
|
201
|
+
throw new Error("webhooks endpoints update requires --url, --events, --name, or a delivery-scope flag.");
|
|
202
|
+
}
|
|
203
|
+
const response = await client.webhooks.updateEndpoint(endpointId, input);
|
|
204
|
+
if (jsonFlag) {
|
|
205
|
+
printJson(response);
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
writeEndpointLine(response.data);
|
|
209
|
+
}
|
|
210
|
+
async function disableEndpoint(client, endpointId, jsonFlag) {
|
|
211
|
+
const response = await client.webhooks.updateEndpoint(endpointId, {
|
|
212
|
+
status: "disabled",
|
|
213
|
+
});
|
|
214
|
+
if (jsonFlag) {
|
|
215
|
+
printJson(response);
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
writeEndpointLine(response.data);
|
|
219
|
+
}
|
|
220
|
+
async function rotateEndpointSecret(client, endpointId, parsedArgs, jsonFlag) {
|
|
221
|
+
const previousSecretTtlSeconds = getPositiveIntegerFlag(parsedArgs, "previous-secret-ttl");
|
|
222
|
+
const response = await client.webhooks.rotateEndpointSecret(endpointId, previousSecretTtlSeconds == null ? {} : { previousSecretTtlSeconds });
|
|
223
|
+
if (jsonFlag) {
|
|
224
|
+
printJson(response);
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
writeEndpointSecret(response.data);
|
|
228
|
+
}
|
|
229
|
+
async function sendEndpointTestEvent(client, endpointId, parsedArgs, jsonFlag) {
|
|
230
|
+
if (jsonFlag && hasFlag(parsedArgs, "watch-delivery")) {
|
|
231
|
+
throw new Error("Use either --json or --watch-delivery for webhooks endpoints test, not both.");
|
|
232
|
+
}
|
|
233
|
+
const watchDelivery = hasFlag(parsedArgs, "watch-delivery");
|
|
234
|
+
const timeoutMs = getPositiveIntegerFlag(parsedArgs, "timeout") ?? 30_000;
|
|
235
|
+
const response = await client.webhooks.sendTestEvent(endpointId);
|
|
236
|
+
if (jsonFlag) {
|
|
237
|
+
printJson(response);
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
process.stdout.write(`event_id\t${response.data.event_id}\n`);
|
|
241
|
+
for (const deliveryId of response.data.delivery_ids) {
|
|
242
|
+
process.stdout.write(`delivery_id\t${deliveryId}\n`);
|
|
243
|
+
}
|
|
244
|
+
if (watchDelivery) {
|
|
245
|
+
await watchTestDeliveries(client, response.data.event_id, timeoutMs);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
async function watchTestDeliveries(client, eventId, timeoutMs) {
|
|
249
|
+
const deadline = Date.now() + timeoutMs;
|
|
250
|
+
for (;;) {
|
|
251
|
+
const deliveries = await client.webhooks.listDeliveries({ eventId });
|
|
252
|
+
for (const delivery of deliveries.items) {
|
|
253
|
+
writeDeliveryLine(delivery);
|
|
254
|
+
}
|
|
255
|
+
if (deliveries.items.length > 0 &&
|
|
256
|
+
deliveries.items.every((delivery) => TERMINAL_DELIVERY_STATUSES.has(delivery.status))) {
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
if (Date.now() >= deadline) {
|
|
260
|
+
throw new Error("Timed out waiting for webhook test delivery.");
|
|
261
|
+
}
|
|
262
|
+
await sleep(Math.min(1000, Math.max(0, deadline - Date.now())));
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
async function listDeliveries(client, parsedArgs, jsonFlag) {
|
|
266
|
+
const params = {};
|
|
267
|
+
const endpointId = getOptionalStringFlagValue(parsedArgs, "endpoint");
|
|
268
|
+
const eventId = getOptionalStringFlagValue(parsedArgs, "event");
|
|
269
|
+
const status = getDeliveryStatusFlag(parsedArgs);
|
|
270
|
+
const limit = getPositiveLimitFlag(parsedArgs);
|
|
271
|
+
if (endpointId !== undefined) {
|
|
272
|
+
params.endpointId = endpointId;
|
|
273
|
+
}
|
|
274
|
+
if (eventId !== undefined) {
|
|
275
|
+
params.eventId = eventId;
|
|
276
|
+
}
|
|
277
|
+
if (status !== undefined) {
|
|
278
|
+
params.status = status;
|
|
279
|
+
}
|
|
280
|
+
if (limit !== undefined) {
|
|
281
|
+
params.limit = limit;
|
|
282
|
+
}
|
|
283
|
+
const response = await client.webhooks.listDeliveries(params);
|
|
284
|
+
if (jsonFlag) {
|
|
285
|
+
printJson(response);
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
for (const delivery of response.items) {
|
|
289
|
+
writeDeliveryLine(delivery);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
async function replayDelivery(client, deliveryId, jsonFlag) {
|
|
293
|
+
const response = await client.webhooks.replayDelivery(deliveryId);
|
|
294
|
+
if (jsonFlag) {
|
|
295
|
+
printJson(response);
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
process.stdout.write(`delivery_id\t${response.data.delivery_id}\n`);
|
|
299
|
+
}
|
|
300
|
+
function requireEndpointId(parsedArgs) {
|
|
301
|
+
const endpointId = parsedArgs.positionals[3];
|
|
302
|
+
if (endpointId == null || endpointId.trim() === "") {
|
|
303
|
+
throw new Error("webhooks endpoints command requires <endpoint-id>.");
|
|
304
|
+
}
|
|
305
|
+
return endpointId;
|
|
306
|
+
}
|
|
307
|
+
function requireDeliveryId(parsedArgs) {
|
|
308
|
+
const deliveryId = parsedArgs.positionals[3];
|
|
309
|
+
if (deliveryId == null || deliveryId.trim() === "") {
|
|
310
|
+
throw new Error("webhooks deliveries replay requires <delivery-id>.");
|
|
311
|
+
}
|
|
312
|
+
return deliveryId;
|
|
313
|
+
}
|
|
314
|
+
export async function runWebhookCommand({ apiClient, parsedArgs, }) {
|
|
315
|
+
const resource = parsedArgs.positionals[1] ?? "endpoints";
|
|
316
|
+
if (resource === "deliveries") {
|
|
317
|
+
const action = parsedArgs.positionals[2] ?? "list";
|
|
318
|
+
const jsonFlag = hasFlag(parsedArgs, "json");
|
|
319
|
+
switch (action) {
|
|
320
|
+
case "list":
|
|
321
|
+
await listDeliveries(apiClient, parsedArgs, jsonFlag);
|
|
322
|
+
return;
|
|
323
|
+
case "replay":
|
|
324
|
+
await replayDelivery(apiClient, requireDeliveryId(parsedArgs), jsonFlag);
|
|
325
|
+
return;
|
|
326
|
+
default:
|
|
327
|
+
throw new Error(`Unknown webhooks deliveries command "${action}". Expected list or replay.`);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
if (resource !== "endpoints") {
|
|
331
|
+
throw new Error(`Unknown webhooks resource "${resource}". Expected endpoints or deliveries.`);
|
|
332
|
+
}
|
|
333
|
+
const action = parsedArgs.positionals[2] ?? "list";
|
|
334
|
+
const jsonFlag = hasFlag(parsedArgs, "json");
|
|
335
|
+
switch (action) {
|
|
336
|
+
case "list":
|
|
337
|
+
await listEndpoints(apiClient, jsonFlag);
|
|
338
|
+
return;
|
|
339
|
+
case "create":
|
|
340
|
+
await createEndpoint(apiClient, parsedArgs, jsonFlag);
|
|
341
|
+
return;
|
|
342
|
+
case "get":
|
|
343
|
+
await getEndpoint(apiClient, requireEndpointId(parsedArgs), jsonFlag);
|
|
344
|
+
return;
|
|
345
|
+
case "update":
|
|
346
|
+
await updateEndpoint(apiClient, requireEndpointId(parsedArgs), parsedArgs, jsonFlag);
|
|
347
|
+
return;
|
|
348
|
+
case "disable":
|
|
349
|
+
await disableEndpoint(apiClient, requireEndpointId(parsedArgs), jsonFlag);
|
|
350
|
+
return;
|
|
351
|
+
case "rotate-secret":
|
|
352
|
+
await rotateEndpointSecret(apiClient, requireEndpointId(parsedArgs), parsedArgs, jsonFlag);
|
|
353
|
+
return;
|
|
354
|
+
case "test":
|
|
355
|
+
await sendEndpointTestEvent(apiClient, requireEndpointId(parsedArgs), parsedArgs, jsonFlag);
|
|
356
|
+
return;
|
|
357
|
+
default:
|
|
358
|
+
throw new Error(`Unknown webhooks endpoints command "${action}". Expected list, create, get, update, disable, rotate-secret, or test.`);
|
|
359
|
+
}
|
|
360
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@andocorp/cli",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Ando CLI - agent-first terminal commands",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -22,13 +22,13 @@
|
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@napi-rs/keyring": "^1.3.0",
|
|
25
|
-
"@andocorp/sdk": "0.2.
|
|
25
|
+
"@andocorp/sdk": "0.2.1"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@types/node": "^25.9.
|
|
29
|
-
"@vitest/coverage-v8": "^4.1.
|
|
28
|
+
"@types/node": "^25.9.4",
|
|
29
|
+
"@vitest/coverage-v8": "^4.1.9",
|
|
30
30
|
"typescript": "^6.0.3",
|
|
31
|
-
"vitest": "^4.1.
|
|
31
|
+
"vitest": "^4.1.9"
|
|
32
32
|
},
|
|
33
33
|
"scripts": {
|
|
34
34
|
"build": "cd ../sdk && pnpm run build && cd ../cli && rm -rf dist && tsc && chmod +x ./dist/index.js",
|