activitysmith-cli 1.3.1 → 1.6.0

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 +97 -1
  2. package/package.json +2 -2
  3. package/src/cli.js +139 -13
package/README.md CHANGED
@@ -15,6 +15,8 @@ CLI wrapper for the ActivitySmith API using the official Node SDK.
15
15
  - [Start & Update Live Activity](#start--update-live-activity)
16
16
  - [End Live Activity](#end-live-activity)
17
17
  - [Live Activity Action](#live-activity-action)
18
+ - [Icons and Badges](#icons-and-badges)
19
+ - [Live Activity Colors](#live-activity-colors)
18
20
  - [Channels](#channels)
19
21
  - [Widgets](#widgets)
20
22
  - [Aliases](#aliases)
@@ -135,12 +137,13 @@ activitysmith push \
135
137
 
136
138
  ## Live Activities
137
139
 
138
- There are four types of Live Activities:
140
+ There are five types of Live Activities:
139
141
 
140
142
  - `stats`: best for showing business numbers side by side, such as revenue, sales, new users, conversion, refunds, or any other value you want visible at a glance
141
143
  - `metrics`: best for live percentage values that change often, like server CPU, memory usage, disk usage, or error rate
142
144
  - `segmented_progress`: best for anything that moves through clear stages, like deployments, onboarding flows, backups, ETL pipelines, migrations, and AI agent runs
143
145
  - `progress`: best for tracking real-time progress with percentage, like tasks, backups, migrations, syncs, or uploads
146
+ - `alert`: best for status updates, such as feature adoption, reactivation, onboarding blockers, incidents, escalations, and other operational states
144
147
 
145
148
  ### Start & Update Live Activity
146
149
 
@@ -237,6 +240,33 @@ activitysmith activity stream search-reindex \
237
240
  }'
238
241
  ```
239
242
 
243
+ #### Alert
244
+
245
+ <p align="center">
246
+ <img
247
+ src="https://cdn.activitysmith.com/features/alert-live-activity.png"
248
+ alt="Alert Live Activity stream example"
249
+ width="680"
250
+ />
251
+ </p>
252
+
253
+ ```bash
254
+ activitysmith activity stream customer-ops \
255
+ --content-state '{
256
+ "title": "Reactivation",
257
+ "message": "Lumen came back after 2 weeks",
258
+ "type": "alert",
259
+ "icon": {
260
+ "symbol": "cloud.sun",
261
+ "color": "yellow"
262
+ },
263
+ "badge": {
264
+ "title": "Customer",
265
+ "color": "magenta"
266
+ }
267
+ }'
268
+ ```
269
+
240
270
  ### End Live Activity
241
271
 
242
272
  Call `activity end-stream` with the same `stream_key` to dismiss the Live Activity. You can include final values before it is removed. By default, iOS removes the Live Activity after two minutes. Set `autoDismissMinutes` to choose a different dismissal time, including `0` for immediate dismissal.
@@ -258,6 +288,7 @@ activitysmith activity end-stream prod-web-1 \
258
288
  ### Live Activity Action
259
289
 
260
290
  Live Activities can include one optional action button. Use it to open a URL from the Live Activity or trigger a backend webhook.
291
+ For Alert Live Activities, set `color` in `--content-state` to tint the action button. `icon.color` and `badge.color` only affect the icon and badge.
261
292
 
262
293
  <p align="center">
263
294
  <img
@@ -310,6 +341,71 @@ activitysmith activity stream search-reindex \
310
341
  }'
311
342
  ```
312
343
 
344
+ ### Icons and Badges
345
+
346
+ Add more context to Live Activities with icons and badges.
347
+
348
+ #### Icon
349
+
350
+ Supported Live Activity types: `stats`, `metrics`, `progress`, `segmented_progress`, and `alert`.
351
+
352
+ <p align="center">
353
+ <img
354
+ src="https://cdn.activitysmith.com/features/metrics-live-activity-with-icon.png"
355
+ alt="Metrics Live Activity with an SF Symbol icon on the iPhone Lock Screen"
356
+ width="680"
357
+ />
358
+ </p>
359
+
360
+ ```bash
361
+ activitysmith activity stream prod-web-1 \
362
+ --content-state '{
363
+ "title": "Server Health",
364
+ "subtitle": "prod-web-1",
365
+ "type": "metrics",
366
+ "icon": { "symbol": "server.rack", "color": "blue" },
367
+ "metrics": [
368
+ { "label": "CPU", "value": 18, "unit": "%" },
369
+ { "label": "MEM", "value": 42, "unit": "%" }
370
+ ]
371
+ }'
372
+ ```
373
+
374
+ The `icon.symbol` value is an Apple SF Symbol name. Browse the catalog with one of these tools:
375
+
376
+ - [ActivitySmith app](https://apps.apple.com/us/app/activitysmith/id6752254835) - Open Settings -> SF Symbols to browse 45 hand-picked icons ready to use
377
+ - [SF Symbols](https://developer.apple.com/sf-symbols/) - Apple's official macOS app
378
+ - [Interactful](https://apps.apple.com/app/interactful/id1528095640) - free third-party iOS app listing all SF Symbols under Foundations -> Iconography
379
+
380
+ #### Badge
381
+
382
+ Badges are supported by `alert`, `progress`, and `segmented_progress` Live Activities.
383
+
384
+ <p align="center">
385
+ <img
386
+ src="https://cdn.activitysmith.com/features/progress-live-activity-with-badge.png"
387
+ alt="Progress Live Activity with a badge on the iPhone Lock Screen"
388
+ width="680"
389
+ />
390
+ </p>
391
+
392
+ ```bash
393
+ activitysmith activity stream nightly-database-backup \
394
+ --content-state '{
395
+ "title": "Nightly Database Backup",
396
+ "subtitle": "verify restore",
397
+ "type": "progress",
398
+ "badge": { "title": "S3", "color": "cyan" },
399
+ "percentage": 62
400
+ }'
401
+ ```
402
+
403
+ ### Live Activity Colors
404
+
405
+ Choose from these colors for the Live Activity accent, including progress bars and action buttons, or apply them to an individual icon or badge:
406
+
407
+ `lime`, `green`, `cyan`, `blue`, `purple`, `magenta`, `red`, `orange`, `yellow`, `gray`
408
+
313
409
  ## Channels
314
410
 
315
411
  Channels are used to target specific team members or devices. Can be used for both push notifications and live activities.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "activitysmith-cli",
3
- "version": "1.3.1",
3
+ "version": "1.6.0",
4
4
  "description": "Command-line interface for ActivitySmith. Send push notifications and manage Live Activities from your terminal.",
5
5
  "keywords": [
6
6
  "activitysmith",
@@ -40,7 +40,7 @@
40
40
  "lint": "node --check src/cli.js"
41
41
  },
42
42
  "dependencies": {
43
- "activitysmith": "^1.3.1",
43
+ "activitysmith": "^1.6.0",
44
44
  "commander": "^12.1.0"
45
45
  }
46
46
  }
package/src/cli.js CHANGED
@@ -97,6 +97,37 @@ const normalizeHttpsUrl = (value, label) => {
97
97
  return parsed.toString();
98
98
  };
99
99
 
100
+ const normalizeUrlWithSchemes = (value, label, schemes) => {
101
+ if (typeof value !== "string" || value.trim().length === 0) {
102
+ throw new Error(`${label} must be a non-empty string`);
103
+ }
104
+
105
+ let parsed;
106
+ try {
107
+ parsed = new URL(value.trim());
108
+ } catch {
109
+ throw new Error(`${label} must be a valid URL`);
110
+ }
111
+
112
+ const allowedProtocols = schemes.map((scheme) => `${scheme}:`);
113
+ if (!allowedProtocols.includes(parsed.protocol)) {
114
+ throw new Error(`${label} must use ${schemes.join(" or ")}`);
115
+ }
116
+
117
+ return parsed.toString();
118
+ };
119
+
120
+ const normalizeActionUrl = (value, label, type) => {
121
+ if (type === "open_url") {
122
+ return normalizeUrlWithSchemes(value, label, ["https", "shortcuts"]);
123
+ }
124
+
125
+ return normalizeHttpsUrl(value, label);
126
+ };
127
+
128
+ const normalizeOpenUrl = (value, label) =>
129
+ normalizeUrlWithSchemes(value, label, ["https", "shortcuts"]);
130
+
100
131
  const addContentStateOptions = (command, { includeAutoDismiss } = {}) => {
101
132
  command
102
133
  .option("--content-state <json>", "Content state as JSON string")
@@ -106,6 +137,11 @@ const addContentStateOptions = (command, { includeAutoDismiss } = {}) => {
106
137
  .option("--title <title>", "Content state title")
107
138
  .option("--subtitle <subtitle>", "Content state subtitle")
108
139
  .option("--type <type>", "Content state type")
140
+ .option("--message <message>", "Alert message")
141
+ .option("--icon-symbol <symbol>", "SF Symbol name")
142
+ .option("--icon-color <color>", "Icon color")
143
+ .option("--badge-title <title>", "Badge title")
144
+ .option("--badge-color <color>", "Badge color")
109
145
  .option(
110
146
  "--number-of-steps <number>",
111
147
  "Content state number of steps",
@@ -236,9 +272,10 @@ const isNonEmptyString = (value) =>
236
272
  const hasOwn = (object, key) =>
237
273
  Object.prototype.hasOwnProperty.call(object, key);
238
274
 
239
- const liveActivityMetricColors = new Set([
275
+ const liveActivityColors = new Set([
240
276
  "blue",
241
277
  "cyan",
278
+ "gray",
242
279
  "green",
243
280
  "lime",
244
281
  "magenta",
@@ -248,6 +285,8 @@ const liveActivityMetricColors = new Set([
248
285
  "yellow",
249
286
  ]);
250
287
 
288
+ const liveActivityColorList = [...liveActivityColors].join(", ");
289
+
251
290
  const validateContentState = (contentState, mode) => {
252
291
  const normalizedType =
253
292
  typeof contentState.type === "string" ? contentState.type.trim() : undefined;
@@ -261,13 +300,17 @@ const validateContentState = (contentState, mode) => {
261
300
  normalizedType !== "segmented_progress" &&
262
301
  normalizedType !== "progress" &&
263
302
  normalizedType !== "metrics" &&
264
- normalizedType !== "stats"
303
+ normalizedType !== "stats" &&
304
+ normalizedType !== "alert"
265
305
  ) {
266
306
  throw new Error(
267
- "contentState.type must be one of: segmented_progress, progress, metrics, stats"
307
+ "contentState.type must be one of: segmented_progress, progress, metrics, stats, alert"
268
308
  );
269
309
  }
270
310
 
311
+ const hasMessage = hasOwn(contentState, "message");
312
+ const hasIcon = hasOwn(contentState, "icon");
313
+ const hasBadge = hasOwn(contentState, "badge");
271
314
  const hasNumberOfSteps = hasOwn(contentState, "numberOfSteps");
272
315
  const hasCurrentStep = hasOwn(contentState, "currentStep");
273
316
  const hasPercentage = hasOwn(contentState, "percentage");
@@ -303,6 +346,41 @@ const validateContentState = (contentState, mode) => {
303
346
 
304
347
  const hasSegmentedFields = hasNumberOfSteps || hasCurrentStep || hasStepColor;
305
348
  const hasProgressFields = hasPercentage || hasValue || hasUpperLimit;
349
+ const hasAlertFields = hasMessage || hasIcon || hasBadge;
350
+
351
+ if (hasIcon) {
352
+ assertPlainObject(contentState.icon, "contentState.icon");
353
+ if (!isNonEmptyString(contentState.icon.symbol)) {
354
+ throw new Error("contentState.icon.symbol is required");
355
+ }
356
+ if (contentState.icon.color !== undefined) {
357
+ if (!isNonEmptyString(contentState.icon.color)) {
358
+ throw new Error("contentState.icon.color must be a string");
359
+ }
360
+ if (!liveActivityColors.has(contentState.icon.color.trim())) {
361
+ throw new Error(
362
+ `contentState.icon.color must be one of: ${liveActivityColorList}`
363
+ );
364
+ }
365
+ }
366
+ }
367
+
368
+ if (hasBadge) {
369
+ assertPlainObject(contentState.badge, "contentState.badge");
370
+ if (!isNonEmptyString(contentState.badge.title)) {
371
+ throw new Error("contentState.badge.title is required");
372
+ }
373
+ if (contentState.badge.color !== undefined) {
374
+ if (!isNonEmptyString(contentState.badge.color)) {
375
+ throw new Error("contentState.badge.color must be a string");
376
+ }
377
+ if (!liveActivityColors.has(contentState.badge.color.trim())) {
378
+ throw new Error(
379
+ `contentState.badge.color must be one of: ${liveActivityColorList}`
380
+ );
381
+ }
382
+ }
383
+ }
306
384
 
307
385
  if (hasSegmentedFields && hasProgressFields) {
308
386
  throw new Error(
@@ -316,6 +394,15 @@ const validateContentState = (contentState, mode) => {
316
394
  );
317
395
  }
318
396
 
397
+ if (
398
+ hasAlertFields &&
399
+ (hasMetrics || hasSegmentedFields || hasProgressFields || hasStepColor)
400
+ ) {
401
+ throw new Error(
402
+ "Do not mix alert fields with metrics, segmented_progress, or progress fields in the same contentState"
403
+ );
404
+ }
405
+
319
406
  if (hasMetrics) {
320
407
  if (!Array.isArray(contentState.metrics) || contentState.metrics.length === 0) {
321
408
  throw new Error("contentState.metrics must be a non-empty array");
@@ -348,11 +435,9 @@ const validateContentState = (contentState, mode) => {
348
435
  if (!isNonEmptyString(metric.color)) {
349
436
  throw new Error(`contentState.metrics[${index}].color must be a string`);
350
437
  }
351
- if (!liveActivityMetricColors.has(metric.color.trim())) {
438
+ if (!liveActivityColors.has(metric.color.trim())) {
352
439
  throw new Error(
353
- `contentState.metrics[${index}].color must be one of: ${[
354
- ...liveActivityMetricColors,
355
- ].join(", ")}`
440
+ `contentState.metrics[${index}].color must be one of: ${liveActivityColorList}`
356
441
  );
357
442
  }
358
443
  }
@@ -382,6 +467,13 @@ const validateContentState = (contentState, mode) => {
382
467
  return;
383
468
  }
384
469
 
470
+ if (effectiveType === "alert") {
471
+ if (!isNonEmptyString(contentState.message)) {
472
+ throw new Error(`alert ${mode} requires contentState.message`);
473
+ }
474
+ return;
475
+ }
476
+
385
477
  if (!hasPercentage && !hasValue) {
386
478
  throw new Error(
387
479
  `progress ${mode} requires contentState.percentage, or contentState.value with contentState.upperLimit`
@@ -415,9 +507,16 @@ const validateContentState = (contentState, mode) => {
415
507
  return;
416
508
  }
417
509
 
418
- if (!hasSegmentedFields && !hasProgressFields && !hasMetrics) {
510
+ if (effectiveType === "alert") {
511
+ if (!isNonEmptyString(contentState.message)) {
512
+ throw new Error(`alert ${mode} requires contentState.message`);
513
+ }
514
+ return;
515
+ }
516
+
517
+ if (!hasSegmentedFields && !hasProgressFields && !hasMetrics && !hasAlertFields) {
419
518
  throw new Error(
420
- `contentState for activity ${mode} must include metrics, segmented_progress fields, or progress fields`
519
+ `contentState for activity ${mode} must include metrics, segmented_progress fields, progress fields, or alert fields`
421
520
  );
422
521
  }
423
522
 
@@ -436,6 +535,10 @@ const validateContentState = (contentState, mode) => {
436
535
  `progress ${mode} requires contentState.percentage, or contentState.value with contentState.upperLimit`
437
536
  );
438
537
  }
538
+
539
+ if (hasAlertFields && !isNonEmptyString(contentState.message)) {
540
+ throw new Error(`alert ${mode} requires contentState.message`);
541
+ }
439
542
  };
440
543
 
441
544
  const parseAction = (value, label) => {
@@ -457,7 +560,7 @@ const parseAction = (value, label) => {
457
560
  const action = {
458
561
  title: value.title.trim(),
459
562
  type: normalizedType,
460
- url: normalizeHttpsUrl(value.url, `${label}.url`),
563
+ url: normalizeActionUrl(value.url, `${label}.url`, normalizedType),
461
564
  };
462
565
 
463
566
  if (value.method !== undefined) {
@@ -560,6 +663,30 @@ const buildContentStateFromOptions = (options) => {
560
663
  contentState.type = options.type;
561
664
  }
562
665
 
666
+ if (options.message !== undefined) {
667
+ contentState.message = options.message;
668
+ }
669
+
670
+ if (options.iconSymbol !== undefined || options.iconColor !== undefined) {
671
+ contentState.icon = {};
672
+ if (options.iconSymbol !== undefined) {
673
+ contentState.icon.symbol = options.iconSymbol;
674
+ }
675
+ if (options.iconColor !== undefined) {
676
+ contentState.icon.color = options.iconColor;
677
+ }
678
+ }
679
+
680
+ if (options.badgeTitle !== undefined || options.badgeColor !== undefined) {
681
+ contentState.badge = {};
682
+ if (options.badgeTitle !== undefined) {
683
+ contentState.badge.title = options.badgeTitle;
684
+ }
685
+ if (options.badgeColor !== undefined) {
686
+ contentState.badge.color = options.badgeColor;
687
+ }
688
+ }
689
+
563
690
  if (options.numberOfSteps !== undefined) {
564
691
  contentState.numberOfSteps = options.numberOfSteps;
565
692
  }
@@ -907,7 +1034,7 @@ program
907
1034
  "--media <url>",
908
1035
  "HTTPS URL for image, audio, or video shown when the notification is expanded"
909
1036
  )
910
- .option("--redirection <url>", "HTTPS URL opened when notification is tapped")
1037
+ .option("--redirection <url>", "HTTPS or shortcuts:// URL opened when notification is tapped")
911
1038
  .option("--actions <json>", "Actions JSON array (max 4)")
912
1039
  .option("--actions-file <path>", "Path to actions JSON array file")
913
1040
  .option(
@@ -938,7 +1065,7 @@ program
938
1065
  : undefined,
939
1066
  redirection:
940
1067
  options.redirection !== undefined
941
- ? normalizeHttpsUrl(options.redirection, "redirection")
1068
+ ? normalizeOpenUrl(options.redirection, "redirection")
942
1069
  : undefined,
943
1070
  actions,
944
1071
  },
@@ -957,7 +1084,6 @@ program
957
1084
  response?.devicesNotified !== undefined
958
1085
  ? `Devices notified: ${response.devicesNotified}`
959
1086
  : null,
960
- response?.timestamp ? `Timestamp: ${response.timestamp}` : null,
961
1087
  ]);
962
1088
  } catch (error) {
963
1089
  await handleError(error, globalOptions);