activitysmith-cli 0.1.1 → 0.1.3
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 +10 -3
- package/package.json +1 -1
- package/src/cli.js +67 -17
package/README.md
CHANGED
|
@@ -23,14 +23,16 @@ activitysmith --help
|
|
|
23
23
|
```bash
|
|
24
24
|
activitysmith push \
|
|
25
25
|
--title "Build Failed" \
|
|
26
|
-
--message "CI pipeline failed on main branch"
|
|
26
|
+
--message "CI pipeline failed on main branch" \
|
|
27
|
+
--channels "devs,ops"
|
|
27
28
|
```
|
|
28
29
|
|
|
29
30
|
### Start Live Activity
|
|
30
31
|
|
|
31
32
|
```bash
|
|
32
33
|
activitysmith activity start \
|
|
33
|
-
--content-state '{"title":"Deploy","subtitle":"start","numberOfSteps":4,"currentStep":1,"type":"segmented_progress","color":"yellow"}'
|
|
34
|
+
--content-state '{"title":"Deploy","subtitle":"start","numberOfSteps":4,"currentStep":1,"type":"segmented_progress","color":"yellow"}' \
|
|
35
|
+
--channels "devs,ops"
|
|
34
36
|
```
|
|
35
37
|
|
|
36
38
|
Or use flags:
|
|
@@ -42,7 +44,8 @@ activitysmith activity start \
|
|
|
42
44
|
--number-of-steps 4 \
|
|
43
45
|
--current-step 1 \
|
|
44
46
|
--type segmented_progress \
|
|
45
|
-
--color yellow
|
|
47
|
+
--color yellow \
|
|
48
|
+
--channels "devs,ops"
|
|
46
49
|
```
|
|
47
50
|
|
|
48
51
|
### Update Live Activity
|
|
@@ -113,6 +116,10 @@ Or use flags to build the payload:
|
|
|
113
116
|
- `--step-color <color>`
|
|
114
117
|
- `--auto-dismiss-minutes <number>`
|
|
115
118
|
|
|
119
|
+
Targeting options:
|
|
120
|
+
|
|
121
|
+
- `--channels <comma-separated-slugs>` (for `push` and `activity start`)
|
|
122
|
+
|
|
116
123
|
Required fields:
|
|
117
124
|
|
|
118
125
|
- `activity start`: `title`, `numberOfSteps`, `currentStep`, `type`
|
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -2,15 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
import { Command, InvalidArgumentError } from "commander";
|
|
4
4
|
import ActivitySmith from "activitysmith";
|
|
5
|
+
import { createRequire } from "module";
|
|
5
6
|
import { readFile } from "fs/promises";
|
|
6
7
|
import { resolve } from "path";
|
|
7
8
|
|
|
9
|
+
const require = createRequire(import.meta.url);
|
|
10
|
+
const { version } = require("../package.json");
|
|
11
|
+
|
|
8
12
|
const program = new Command();
|
|
9
13
|
|
|
10
14
|
program
|
|
11
15
|
.name("activitysmith-cli")
|
|
12
16
|
.description("CLI for ActivitySmith API")
|
|
13
|
-
.version(
|
|
17
|
+
.version(version)
|
|
14
18
|
.option(
|
|
15
19
|
"--api-key <key>",
|
|
16
20
|
"ActivitySmith API key (defaults to ACTIVITYSMITH_API_KEY)"
|
|
@@ -25,6 +29,23 @@ const parseIntegerOption = (label) => (value) => {
|
|
|
25
29
|
return parsed;
|
|
26
30
|
};
|
|
27
31
|
|
|
32
|
+
const parseChannelsOption = (value) => {
|
|
33
|
+
if (typeof value !== "string") {
|
|
34
|
+
throw new InvalidArgumentError("channels must be a comma-separated string");
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const channels = value
|
|
38
|
+
.split(",")
|
|
39
|
+
.map((channel) => channel.trim())
|
|
40
|
+
.filter((channel) => channel.length > 0);
|
|
41
|
+
|
|
42
|
+
if (channels.length === 0) {
|
|
43
|
+
throw new InvalidArgumentError("channels must contain at least one channel slug");
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return channels;
|
|
47
|
+
};
|
|
48
|
+
|
|
28
49
|
const addContentStateOptions = (command, { includeAutoDismiss } = {}) => {
|
|
29
50
|
command
|
|
30
51
|
.option("--content-state <json>", "Content state as JSON string")
|
|
@@ -172,6 +193,19 @@ const toApiLiveActivityStartRequest = (contentState) => ({
|
|
|
172
193
|
content_state: toApiContentState(contentState),
|
|
173
194
|
});
|
|
174
195
|
|
|
196
|
+
const withTargetChannels = (request, channels) => {
|
|
197
|
+
if (!channels || channels.length === 0) {
|
|
198
|
+
return request;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return {
|
|
202
|
+
...request,
|
|
203
|
+
target: {
|
|
204
|
+
channels,
|
|
205
|
+
},
|
|
206
|
+
};
|
|
207
|
+
};
|
|
208
|
+
|
|
175
209
|
const toApiLiveActivityUpdateRequest = (activityId, contentState) => ({
|
|
176
210
|
activity_id: activityId,
|
|
177
211
|
content_state: toApiContentState(contentState),
|
|
@@ -332,6 +366,11 @@ program
|
|
|
332
366
|
.requiredOption("--title <title>", "Push title")
|
|
333
367
|
.option("--message <message>", "Push message")
|
|
334
368
|
.option("--subtitle <subtitle>", "Push subtitle")
|
|
369
|
+
.option(
|
|
370
|
+
"--channels <channels>",
|
|
371
|
+
"Comma-separated channel slugs (optional)",
|
|
372
|
+
parseChannelsOption
|
|
373
|
+
)
|
|
335
374
|
.action(async (options) => {
|
|
336
375
|
const globalOptions = program.opts();
|
|
337
376
|
|
|
@@ -340,11 +379,14 @@ program
|
|
|
340
379
|
const client = createClient(apiKey);
|
|
341
380
|
|
|
342
381
|
const response = await client.notifications.sendPushNotification({
|
|
343
|
-
pushNotificationRequest:
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
382
|
+
pushNotificationRequest: withTargetChannels(
|
|
383
|
+
{
|
|
384
|
+
title: options.title,
|
|
385
|
+
message: options.message,
|
|
386
|
+
subtitle: options.subtitle,
|
|
387
|
+
},
|
|
388
|
+
options.channels
|
|
389
|
+
),
|
|
348
390
|
});
|
|
349
391
|
|
|
350
392
|
outputResult(response, globalOptions, [
|
|
@@ -370,6 +412,11 @@ addContentStateOptions(
|
|
|
370
412
|
activityCommand
|
|
371
413
|
.command("start")
|
|
372
414
|
.description("Start a Live Activity")
|
|
415
|
+
.option(
|
|
416
|
+
"--channels <channels>",
|
|
417
|
+
"Comma-separated channel slugs (optional)",
|
|
418
|
+
parseChannelsOption
|
|
419
|
+
)
|
|
373
420
|
.action(async (options) => {
|
|
374
421
|
const globalOptions = program.opts();
|
|
375
422
|
|
|
@@ -378,9 +425,12 @@ addContentStateOptions(
|
|
|
378
425
|
const client = createClient(apiKey);
|
|
379
426
|
const contentState = await loadContentState(options);
|
|
380
427
|
|
|
381
|
-
const response = await client.liveActivities.
|
|
382
|
-
|
|
383
|
-
|
|
428
|
+
const response = await client.liveActivities.start(
|
|
429
|
+
withTargetChannels(
|
|
430
|
+
toApiLiveActivityStartRequest(contentState),
|
|
431
|
+
options.channels
|
|
432
|
+
)
|
|
433
|
+
);
|
|
384
434
|
|
|
385
435
|
const activityId = response?.activityId ?? response?.activity_id;
|
|
386
436
|
outputResult(response, globalOptions, [
|
|
@@ -406,12 +456,12 @@ addContentStateOptions(
|
|
|
406
456
|
const client = createClient(apiKey);
|
|
407
457
|
const contentState = await loadContentState(options);
|
|
408
458
|
|
|
409
|
-
const response = await client.liveActivities.
|
|
410
|
-
|
|
459
|
+
const response = await client.liveActivities.update(
|
|
460
|
+
toApiLiveActivityUpdateRequest(
|
|
411
461
|
options.activityId,
|
|
412
462
|
contentState
|
|
413
|
-
)
|
|
414
|
-
|
|
463
|
+
)
|
|
464
|
+
);
|
|
415
465
|
|
|
416
466
|
outputResult(response, globalOptions, [
|
|
417
467
|
"Live Activity updated.",
|
|
@@ -436,12 +486,12 @@ addContentStateOptions(
|
|
|
436
486
|
const client = createClient(apiKey);
|
|
437
487
|
const contentState = await loadContentState(options);
|
|
438
488
|
|
|
439
|
-
const response = await client.liveActivities.
|
|
440
|
-
|
|
489
|
+
const response = await client.liveActivities.end(
|
|
490
|
+
toApiLiveActivityEndRequest(
|
|
441
491
|
options.activityId,
|
|
442
492
|
contentState
|
|
443
|
-
)
|
|
444
|
-
|
|
493
|
+
)
|
|
494
|
+
);
|
|
445
495
|
|
|
446
496
|
outputResult(response, globalOptions, [
|
|
447
497
|
"Live Activity ended.",
|