activitysmith-cli 0.1.1 → 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.
Files changed (3) hide show
  1. package/README.md +10 -3
  2. package/package.json +1 -1
  3. package/src/cli.js +61 -15
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "activitysmith-cli",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Command-line interface for ActivitySmith. Send push notifications, start, update and end live activities directly from your terminal.",
5
5
  "keywords": [
6
6
  "activitysmith",
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.0")
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.sendPushNotification({
343
- pushNotificationRequest: {
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.startLiveActivity({
382
- liveActivityStartRequest: toApiLiveActivityStartRequest(contentState),
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.updateLiveActivity({
410
- liveActivityUpdateRequest: toApiLiveActivityUpdateRequest(
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.endLiveActivity({
440
- liveActivityEndRequest: toApiLiveActivityEndRequest(
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.",