activitysmith-cli 1.3.1 → 1.4.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 +38 -1
  2. package/package.json +2 -2
  3. package/src/cli.js +105 -10
package/README.md CHANGED
@@ -135,12 +135,13 @@ activitysmith push \
135
135
 
136
136
  ## Live Activities
137
137
 
138
- There are four types of Live Activities:
138
+ There are five types of Live Activities:
139
139
 
140
140
  - `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
141
  - `metrics`: best for live percentage values that change often, like server CPU, memory usage, disk usage, or error rate
142
142
  - `segmented_progress`: best for anything that moves through clear stages, like deployments, onboarding flows, backups, ETL pipelines, migrations, and AI agent runs
143
143
  - `progress`: best for tracking real-time progress with percentage, like tasks, backups, migrations, syncs, or uploads
144
+ - `alert`: best for status updates, such as feature adoption, reactivation, onboarding blockers, incidents, escalations, and other operational states
144
145
 
145
146
  ### Start & Update Live Activity
146
147
 
@@ -237,6 +238,41 @@ activitysmith activity stream search-reindex \
237
238
  }'
238
239
  ```
239
240
 
241
+ #### Alert
242
+
243
+ <p align="center">
244
+ <img
245
+ src="https://cdn.activitysmith.com/features/alert-live-activity.png"
246
+ alt="Alert Live Activity stream example"
247
+ width="680"
248
+ />
249
+ </p>
250
+
251
+ ```bash
252
+ activitysmith activity stream customer-ops \
253
+ --content-state '{
254
+ "title": "Reactivation",
255
+ "message": "Lumen came back after 2 weeks",
256
+ "type": "alert",
257
+ "icon": {
258
+ "symbol": "cloud.sun",
259
+ "color": "yellow"
260
+ },
261
+ "badge": {
262
+ "title": "Customer",
263
+ "color": "magenta"
264
+ }
265
+ }'
266
+ ```
267
+
268
+ The `icon.symbol` value is an Apple SF Symbol name. Browse the catalog with one of these tools:
269
+
270
+ - [ActivitySmith app](https://apps.apple.com/us/app/activitysmith/id6752254835) - Open Settings -> SF Symbols to browse 45 hand-picked icons ready to use
271
+ - [SF Symbols](https://developer.apple.com/sf-symbols/) - Apple's official macOS app
272
+ - [Interactful](https://apps.apple.com/app/interactful/id1528095640) - free third-party iOS app listing all SF Symbols under Foundations -> Iconography
273
+
274
+ `icon` and `badge` are optional. If you omit either one, that element is not shown in the Live Activity.
275
+
240
276
  ### End Live Activity
241
277
 
242
278
  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 +294,7 @@ activitysmith activity end-stream prod-web-1 \
258
294
  ### Live Activity Action
259
295
 
260
296
  Live Activities can include one optional action button. Use it to open a URL from the Live Activity or trigger a backend webhook.
297
+ 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
298
 
262
299
  <p align="center">
263
300
  <img
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "activitysmith-cli",
3
- "version": "1.3.1",
3
+ "version": "1.4.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.4.0",
44
44
  "commander": "^12.1.0"
45
45
  }
46
46
  }
package/src/cli.js CHANGED
@@ -106,6 +106,11 @@ const addContentStateOptions = (command, { includeAutoDismiss } = {}) => {
106
106
  .option("--title <title>", "Content state title")
107
107
  .option("--subtitle <subtitle>", "Content state subtitle")
108
108
  .option("--type <type>", "Content state type")
109
+ .option("--message <message>", "Alert message")
110
+ .option("--icon-symbol <symbol>", "Alert SF Symbol name")
111
+ .option("--icon-color <color>", "Alert icon color")
112
+ .option("--badge-title <title>", "Alert badge title")
113
+ .option("--badge-color <color>", "Alert badge color")
109
114
  .option(
110
115
  "--number-of-steps <number>",
111
116
  "Content state number of steps",
@@ -236,9 +241,10 @@ const isNonEmptyString = (value) =>
236
241
  const hasOwn = (object, key) =>
237
242
  Object.prototype.hasOwnProperty.call(object, key);
238
243
 
239
- const liveActivityMetricColors = new Set([
244
+ const liveActivityColors = new Set([
240
245
  "blue",
241
246
  "cyan",
247
+ "gray",
242
248
  "green",
243
249
  "lime",
244
250
  "magenta",
@@ -248,6 +254,8 @@ const liveActivityMetricColors = new Set([
248
254
  "yellow",
249
255
  ]);
250
256
 
257
+ const liveActivityColorList = [...liveActivityColors].join(", ");
258
+
251
259
  const validateContentState = (contentState, mode) => {
252
260
  const normalizedType =
253
261
  typeof contentState.type === "string" ? contentState.type.trim() : undefined;
@@ -261,13 +269,17 @@ const validateContentState = (contentState, mode) => {
261
269
  normalizedType !== "segmented_progress" &&
262
270
  normalizedType !== "progress" &&
263
271
  normalizedType !== "metrics" &&
264
- normalizedType !== "stats"
272
+ normalizedType !== "stats" &&
273
+ normalizedType !== "alert"
265
274
  ) {
266
275
  throw new Error(
267
- "contentState.type must be one of: segmented_progress, progress, metrics, stats"
276
+ "contentState.type must be one of: segmented_progress, progress, metrics, stats, alert"
268
277
  );
269
278
  }
270
279
 
280
+ const hasMessage = hasOwn(contentState, "message");
281
+ const hasIcon = hasOwn(contentState, "icon");
282
+ const hasBadge = hasOwn(contentState, "badge");
271
283
  const hasNumberOfSteps = hasOwn(contentState, "numberOfSteps");
272
284
  const hasCurrentStep = hasOwn(contentState, "currentStep");
273
285
  const hasPercentage = hasOwn(contentState, "percentage");
@@ -303,6 +315,41 @@ const validateContentState = (contentState, mode) => {
303
315
 
304
316
  const hasSegmentedFields = hasNumberOfSteps || hasCurrentStep || hasStepColor;
305
317
  const hasProgressFields = hasPercentage || hasValue || hasUpperLimit;
318
+ const hasAlertFields = hasMessage || hasIcon || hasBadge;
319
+
320
+ if (hasIcon) {
321
+ assertPlainObject(contentState.icon, "contentState.icon");
322
+ if (!isNonEmptyString(contentState.icon.symbol)) {
323
+ throw new Error("contentState.icon.symbol is required");
324
+ }
325
+ if (contentState.icon.color !== undefined) {
326
+ if (!isNonEmptyString(contentState.icon.color)) {
327
+ throw new Error("contentState.icon.color must be a string");
328
+ }
329
+ if (!liveActivityColors.has(contentState.icon.color.trim())) {
330
+ throw new Error(
331
+ `contentState.icon.color must be one of: ${liveActivityColorList}`
332
+ );
333
+ }
334
+ }
335
+ }
336
+
337
+ if (hasBadge) {
338
+ assertPlainObject(contentState.badge, "contentState.badge");
339
+ if (!isNonEmptyString(contentState.badge.title)) {
340
+ throw new Error("contentState.badge.title is required");
341
+ }
342
+ if (contentState.badge.color !== undefined) {
343
+ if (!isNonEmptyString(contentState.badge.color)) {
344
+ throw new Error("contentState.badge.color must be a string");
345
+ }
346
+ if (!liveActivityColors.has(contentState.badge.color.trim())) {
347
+ throw new Error(
348
+ `contentState.badge.color must be one of: ${liveActivityColorList}`
349
+ );
350
+ }
351
+ }
352
+ }
306
353
 
307
354
  if (hasSegmentedFields && hasProgressFields) {
308
355
  throw new Error(
@@ -316,6 +363,15 @@ const validateContentState = (contentState, mode) => {
316
363
  );
317
364
  }
318
365
 
366
+ if (
367
+ hasAlertFields &&
368
+ (hasMetrics || hasSegmentedFields || hasProgressFields || hasStepColor)
369
+ ) {
370
+ throw new Error(
371
+ "Do not mix alert fields with metrics, segmented_progress, or progress fields in the same contentState"
372
+ );
373
+ }
374
+
319
375
  if (hasMetrics) {
320
376
  if (!Array.isArray(contentState.metrics) || contentState.metrics.length === 0) {
321
377
  throw new Error("contentState.metrics must be a non-empty array");
@@ -348,11 +404,9 @@ const validateContentState = (contentState, mode) => {
348
404
  if (!isNonEmptyString(metric.color)) {
349
405
  throw new Error(`contentState.metrics[${index}].color must be a string`);
350
406
  }
351
- if (!liveActivityMetricColors.has(metric.color.trim())) {
407
+ if (!liveActivityColors.has(metric.color.trim())) {
352
408
  throw new Error(
353
- `contentState.metrics[${index}].color must be one of: ${[
354
- ...liveActivityMetricColors,
355
- ].join(", ")}`
409
+ `contentState.metrics[${index}].color must be one of: ${liveActivityColorList}`
356
410
  );
357
411
  }
358
412
  }
@@ -382,6 +436,13 @@ const validateContentState = (contentState, mode) => {
382
436
  return;
383
437
  }
384
438
 
439
+ if (effectiveType === "alert") {
440
+ if (!isNonEmptyString(contentState.message)) {
441
+ throw new Error(`alert ${mode} requires contentState.message`);
442
+ }
443
+ return;
444
+ }
445
+
385
446
  if (!hasPercentage && !hasValue) {
386
447
  throw new Error(
387
448
  `progress ${mode} requires contentState.percentage, or contentState.value with contentState.upperLimit`
@@ -415,9 +476,16 @@ const validateContentState = (contentState, mode) => {
415
476
  return;
416
477
  }
417
478
 
418
- if (!hasSegmentedFields && !hasProgressFields && !hasMetrics) {
479
+ if (effectiveType === "alert") {
480
+ if (!isNonEmptyString(contentState.message)) {
481
+ throw new Error(`alert ${mode} requires contentState.message`);
482
+ }
483
+ return;
484
+ }
485
+
486
+ if (!hasSegmentedFields && !hasProgressFields && !hasMetrics && !hasAlertFields) {
419
487
  throw new Error(
420
- `contentState for activity ${mode} must include metrics, segmented_progress fields, or progress fields`
488
+ `contentState for activity ${mode} must include metrics, segmented_progress fields, progress fields, or alert fields`
421
489
  );
422
490
  }
423
491
 
@@ -436,6 +504,10 @@ const validateContentState = (contentState, mode) => {
436
504
  `progress ${mode} requires contentState.percentage, or contentState.value with contentState.upperLimit`
437
505
  );
438
506
  }
507
+
508
+ if (hasAlertFields && !isNonEmptyString(contentState.message)) {
509
+ throw new Error(`alert ${mode} requires contentState.message`);
510
+ }
439
511
  };
440
512
 
441
513
  const parseAction = (value, label) => {
@@ -560,6 +632,30 @@ const buildContentStateFromOptions = (options) => {
560
632
  contentState.type = options.type;
561
633
  }
562
634
 
635
+ if (options.message !== undefined) {
636
+ contentState.message = options.message;
637
+ }
638
+
639
+ if (options.iconSymbol !== undefined || options.iconColor !== undefined) {
640
+ contentState.icon = {};
641
+ if (options.iconSymbol !== undefined) {
642
+ contentState.icon.symbol = options.iconSymbol;
643
+ }
644
+ if (options.iconColor !== undefined) {
645
+ contentState.icon.color = options.iconColor;
646
+ }
647
+ }
648
+
649
+ if (options.badgeTitle !== undefined || options.badgeColor !== undefined) {
650
+ contentState.badge = {};
651
+ if (options.badgeTitle !== undefined) {
652
+ contentState.badge.title = options.badgeTitle;
653
+ }
654
+ if (options.badgeColor !== undefined) {
655
+ contentState.badge.color = options.badgeColor;
656
+ }
657
+ }
658
+
563
659
  if (options.numberOfSteps !== undefined) {
564
660
  contentState.numberOfSteps = options.numberOfSteps;
565
661
  }
@@ -957,7 +1053,6 @@ program
957
1053
  response?.devicesNotified !== undefined
958
1054
  ? `Devices notified: ${response.devicesNotified}`
959
1055
  : null,
960
- response?.timestamp ? `Timestamp: ${response.timestamp}` : null,
961
1056
  ]);
962
1057
  } catch (error) {
963
1058
  await handleError(error, globalOptions);