activitysmith-cli 0.1.0 → 0.1.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.
- package/README.md +50 -4
- package/package.json +1 -1
- package/src/cli.js +61 -15
package/README.md
CHANGED
|
@@ -18,19 +18,34 @@ Set `ACTIVITYSMITH_API_KEY` or pass `--api-key`.
|
|
|
18
18
|
activitysmith --help
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
-
### Send Push
|
|
21
|
+
### Send Push Notification
|
|
22
22
|
|
|
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"
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Or use flags:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
activitysmith activity start \
|
|
42
|
+
--title "Deploy" \
|
|
43
|
+
--subtitle "start" \
|
|
44
|
+
--number-of-steps 4 \
|
|
45
|
+
--current-step 1 \
|
|
46
|
+
--type segmented_progress \
|
|
47
|
+
--color yellow \
|
|
48
|
+
--channels "devs,ops"
|
|
34
49
|
```
|
|
35
50
|
|
|
36
51
|
### Update Live Activity
|
|
@@ -41,6 +56,16 @@ activitysmith activity update \
|
|
|
41
56
|
--content-state '{"title":"Deploy","subtitle":"step 2","currentStep":2}'
|
|
42
57
|
```
|
|
43
58
|
|
|
59
|
+
Or use flags:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
activitysmith activity update \
|
|
63
|
+
--activity-id "<activityId>" \
|
|
64
|
+
--title "Deploy" \
|
|
65
|
+
--subtitle "step 2" \
|
|
66
|
+
--current-step 2
|
|
67
|
+
```
|
|
68
|
+
|
|
44
69
|
### End Live Activity
|
|
45
70
|
|
|
46
71
|
```bash
|
|
@@ -49,12 +74,23 @@ activitysmith activity end \
|
|
|
49
74
|
--content-state '{"title":"Deploy","subtitle":"done","currentStep":4,"autoDismissMinutes":3}'
|
|
50
75
|
```
|
|
51
76
|
|
|
77
|
+
Or use flags:
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
activitysmith activity end \
|
|
81
|
+
--activity-id "<activityId>" \
|
|
82
|
+
--title "Deploy" \
|
|
83
|
+
--subtitle "done" \
|
|
84
|
+
--current-step 4 \
|
|
85
|
+
--auto-dismiss-minutes 3
|
|
86
|
+
```
|
|
87
|
+
|
|
52
88
|
### JSON Output
|
|
53
89
|
|
|
54
90
|
```bash
|
|
55
91
|
activitysmith push --title "Hello" --json
|
|
56
92
|
```
|
|
57
|
-
|
|
93
|
+
|
|
58
94
|
## Aliases
|
|
59
95
|
|
|
60
96
|
The CLI installs two bin names:
|
|
@@ -80,6 +116,16 @@ Or use flags to build the payload:
|
|
|
80
116
|
- `--step-color <color>`
|
|
81
117
|
- `--auto-dismiss-minutes <number>`
|
|
82
118
|
|
|
119
|
+
Targeting options:
|
|
120
|
+
|
|
121
|
+
- `--channels <comma-separated-slugs>` (for `push` and `activity start`)
|
|
122
|
+
|
|
123
|
+
Required fields:
|
|
124
|
+
|
|
125
|
+
- `activity start`: `title`, `numberOfSteps`, `currentStep`, `type`
|
|
126
|
+
- `activity update`: `title`, `currentStep`
|
|
127
|
+
- `activity end`: `title`, `currentStep`
|
|
128
|
+
|
|
83
129
|
## Output
|
|
84
130
|
|
|
85
131
|
Use `--json` for machine-readable output.
|
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -10,7 +10,7 @@ const program = new Command();
|
|
|
10
10
|
program
|
|
11
11
|
.name("activitysmith-cli")
|
|
12
12
|
.description("CLI for ActivitySmith API")
|
|
13
|
-
.version("0.1.
|
|
13
|
+
.version("0.1.1")
|
|
14
14
|
.option(
|
|
15
15
|
"--api-key <key>",
|
|
16
16
|
"ActivitySmith API key (defaults to ACTIVITYSMITH_API_KEY)"
|
|
@@ -25,6 +25,23 @@ const parseIntegerOption = (label) => (value) => {
|
|
|
25
25
|
return parsed;
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
+
const parseChannelsOption = (value) => {
|
|
29
|
+
if (typeof value !== "string") {
|
|
30
|
+
throw new InvalidArgumentError("channels must be a comma-separated string");
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const channels = value
|
|
34
|
+
.split(",")
|
|
35
|
+
.map((channel) => channel.trim())
|
|
36
|
+
.filter((channel) => channel.length > 0);
|
|
37
|
+
|
|
38
|
+
if (channels.length === 0) {
|
|
39
|
+
throw new InvalidArgumentError("channels must contain at least one channel slug");
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return channels;
|
|
43
|
+
};
|
|
44
|
+
|
|
28
45
|
const addContentStateOptions = (command, { includeAutoDismiss } = {}) => {
|
|
29
46
|
command
|
|
30
47
|
.option("--content-state <json>", "Content state as JSON string")
|
|
@@ -172,6 +189,19 @@ const toApiLiveActivityStartRequest = (contentState) => ({
|
|
|
172
189
|
content_state: toApiContentState(contentState),
|
|
173
190
|
});
|
|
174
191
|
|
|
192
|
+
const withTargetChannels = (request, channels) => {
|
|
193
|
+
if (!channels || channels.length === 0) {
|
|
194
|
+
return request;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
return {
|
|
198
|
+
...request,
|
|
199
|
+
target: {
|
|
200
|
+
channels,
|
|
201
|
+
},
|
|
202
|
+
};
|
|
203
|
+
};
|
|
204
|
+
|
|
175
205
|
const toApiLiveActivityUpdateRequest = (activityId, contentState) => ({
|
|
176
206
|
activity_id: activityId,
|
|
177
207
|
content_state: toApiContentState(contentState),
|
|
@@ -332,6 +362,11 @@ program
|
|
|
332
362
|
.requiredOption("--title <title>", "Push title")
|
|
333
363
|
.option("--message <message>", "Push message")
|
|
334
364
|
.option("--subtitle <subtitle>", "Push subtitle")
|
|
365
|
+
.option(
|
|
366
|
+
"--channels <channels>",
|
|
367
|
+
"Comma-separated channel slugs (optional)",
|
|
368
|
+
parseChannelsOption
|
|
369
|
+
)
|
|
335
370
|
.action(async (options) => {
|
|
336
371
|
const globalOptions = program.opts();
|
|
337
372
|
|
|
@@ -339,12 +374,15 @@ program
|
|
|
339
374
|
const apiKey = requireApiKey(globalOptions);
|
|
340
375
|
const client = createClient(apiKey);
|
|
341
376
|
|
|
342
|
-
const response = await client.notifications.
|
|
343
|
-
|
|
377
|
+
const response = await client.notifications.send({
|
|
378
|
+
...withTargetChannels(
|
|
379
|
+
{
|
|
344
380
|
title: options.title,
|
|
345
381
|
message: options.message,
|
|
346
382
|
subtitle: options.subtitle,
|
|
347
|
-
|
|
383
|
+
},
|
|
384
|
+
options.channels
|
|
385
|
+
),
|
|
348
386
|
});
|
|
349
387
|
|
|
350
388
|
outputResult(response, globalOptions, [
|
|
@@ -370,6 +408,11 @@ addContentStateOptions(
|
|
|
370
408
|
activityCommand
|
|
371
409
|
.command("start")
|
|
372
410
|
.description("Start a Live Activity")
|
|
411
|
+
.option(
|
|
412
|
+
"--channels <channels>",
|
|
413
|
+
"Comma-separated channel slugs (optional)",
|
|
414
|
+
parseChannelsOption
|
|
415
|
+
)
|
|
373
416
|
.action(async (options) => {
|
|
374
417
|
const globalOptions = program.opts();
|
|
375
418
|
|
|
@@ -378,9 +421,12 @@ addContentStateOptions(
|
|
|
378
421
|
const client = createClient(apiKey);
|
|
379
422
|
const contentState = await loadContentState(options);
|
|
380
423
|
|
|
381
|
-
const response = await client.liveActivities.
|
|
382
|
-
|
|
383
|
-
|
|
424
|
+
const response = await client.liveActivities.start(
|
|
425
|
+
withTargetChannels(
|
|
426
|
+
toApiLiveActivityStartRequest(contentState),
|
|
427
|
+
options.channels
|
|
428
|
+
)
|
|
429
|
+
);
|
|
384
430
|
|
|
385
431
|
const activityId = response?.activityId ?? response?.activity_id;
|
|
386
432
|
outputResult(response, globalOptions, [
|
|
@@ -406,12 +452,12 @@ addContentStateOptions(
|
|
|
406
452
|
const client = createClient(apiKey);
|
|
407
453
|
const contentState = await loadContentState(options);
|
|
408
454
|
|
|
409
|
-
const response = await client.liveActivities.
|
|
410
|
-
|
|
455
|
+
const response = await client.liveActivities.update(
|
|
456
|
+
toApiLiveActivityUpdateRequest(
|
|
411
457
|
options.activityId,
|
|
412
458
|
contentState
|
|
413
|
-
)
|
|
414
|
-
|
|
459
|
+
)
|
|
460
|
+
);
|
|
415
461
|
|
|
416
462
|
outputResult(response, globalOptions, [
|
|
417
463
|
"Live Activity updated.",
|
|
@@ -436,12 +482,12 @@ addContentStateOptions(
|
|
|
436
482
|
const client = createClient(apiKey);
|
|
437
483
|
const contentState = await loadContentState(options);
|
|
438
484
|
|
|
439
|
-
const response = await client.liveActivities.
|
|
440
|
-
|
|
485
|
+
const response = await client.liveActivities.end(
|
|
486
|
+
toApiLiveActivityEndRequest(
|
|
441
487
|
options.activityId,
|
|
442
488
|
contentState
|
|
443
|
-
)
|
|
444
|
-
|
|
489
|
+
)
|
|
490
|
+
);
|
|
445
491
|
|
|
446
492
|
outputResult(response, globalOptions, [
|
|
447
493
|
"Live Activity ended.",
|