activitysmith-cli 0.1.6 → 0.1.8

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 +109 -31
  2. package/package.json +3 -3
  3. package/src/cli.js +190 -4
package/README.md CHANGED
@@ -44,62 +44,108 @@ activitysmith push \
44
44
  --message "CI pipeline failed on main branch"
45
45
  ```
46
46
 
47
- ### Start Live Activity
47
+ ## Live Activities
48
48
 
49
- ```bash
50
- activitysmith activity start \
51
- --content-state '{"title":"Deploy","subtitle":"start","numberOfSteps":4,"currentStep":1,"type":"segmented_progress","color":"yellow"}' \
52
- --channels "devs,ops"
53
- ```
49
+ Live Activities come in two UI types, but the lifecycle stays the same:
50
+ start the activity, keep the returned `activity_id`, update it as state
51
+ changes, then end it when the work is done.
52
+
53
+ - `segmented_progress`: best for jobs tracked in steps
54
+ - `progress`: best for jobs tracked as a percentage or numeric range
55
+
56
+ ### Shared flow
57
+
58
+ 1. Run `activitysmith activity start ...`.
59
+ 2. Save the returned `activity_id`.
60
+ 3. Run `activitysmith activity update ...` as progress changes.
61
+ 4. Run `activitysmith activity end ...` when the work is finished.
62
+
63
+ You can use `--content-state <json>` for the examples below, or build the same
64
+ payload with flags as documented in `Content State Options`.
65
+
66
+ ### Segmented Progress Type
67
+
68
+ Use `segmented_progress` when progress is easier to follow as steps instead of a
69
+ raw percentage. It fits jobs like deployments, backups, ETL pipelines, and
70
+ checklists where "step 2 of 3" is more useful than "67%".
71
+ `numberOfSteps` is dynamic, so you can increase or decrease it later if the
72
+ workflow changes.
54
73
 
55
- Or use flags:
74
+ #### Start
75
+
76
+ <p align="center">
77
+ <img src="https://cdn.activitysmith.com/features/start-live-activity.png" alt="Segmented progress start example" width="680" />
78
+ </p>
56
79
 
57
80
  ```bash
58
81
  activitysmith activity start \
59
- --title "Deploy" \
60
- --subtitle "start" \
61
- --number-of-steps 4 \
62
- --current-step 1 \
63
- --type segmented_progress \
64
- --color yellow \
82
+ --content-state '{"title":"Nightly database backup","subtitle":"create snapshot","numberOfSteps":3,"currentStep":1,"type":"segmented_progress","color":"yellow"}' \
65
83
  --channels "devs,ops"
66
84
  ```
67
85
 
68
- ### Update Live Activity
86
+ #### Update
87
+
88
+ <p align="center">
89
+ <img src="https://cdn.activitysmith.com/features/update-live-activity.png" alt="Segmented progress update example" width="680" />
90
+ </p>
69
91
 
70
92
  ```bash
71
93
  activitysmith activity update \
72
94
  --activity-id "<activityId>" \
73
- --content-state '{"title":"Deploy","subtitle":"step 2","currentStep":2}'
95
+ --content-state '{"title":"Nightly database backup","subtitle":"upload archive","numberOfSteps":4,"currentStep":2}'
74
96
  ```
75
97
 
76
- Or use flags:
98
+ #### End
99
+
100
+ <p align="center">
101
+ <img src="https://cdn.activitysmith.com/features/end-live-activity.png" alt="Segmented progress end example" width="680" />
102
+ </p>
77
103
 
78
104
  ```bash
79
- activitysmith activity update \
105
+ activitysmith activity end \
80
106
  --activity-id "<activityId>" \
81
- --title "Deploy" \
82
- --subtitle "step 2" \
83
- --current-step 2
107
+ --content-state '{"title":"Nightly database backup","subtitle":"verify restore","numberOfSteps":4,"currentStep":4,"autoDismissMinutes":2}'
84
108
  ```
85
109
 
86
- ### End Live Activity
110
+ ### Progress Type
111
+
112
+ Use `progress` when the state is naturally continuous. It fits charging,
113
+ downloads, sync jobs, uploads, timers, and any flow where a percentage or
114
+ numeric range is the clearest signal.
115
+
116
+ #### Start
117
+
118
+ <p align="center">
119
+ <img src="https://cdn.activitysmith.com/features/progress-live-activity-start.png" alt="Progress start example" width="680" />
120
+ </p>
87
121
 
88
122
  ```bash
89
- activitysmith activity end \
123
+ activitysmith activity start \
124
+ --content-state '{"title":"EV Charging","subtitle":"Added 30 mi range","percentage":15,"type":"progress","color":"lime"}'
125
+ ```
126
+
127
+ #### Update
128
+
129
+ <p align="center">
130
+ <img src="https://cdn.activitysmith.com/features/progress-live-activity-update.png" alt="Progress update example" width="680" />
131
+ </p>
132
+
133
+ ```bash
134
+ activitysmith activity update \
90
135
  --activity-id "<activityId>" \
91
- --content-state '{"title":"Deploy","subtitle":"done","currentStep":4,"autoDismissMinutes":3}'
136
+ --content-state '{"title":"EV Charging","subtitle":"Added 120 mi range","percentage":60}'
92
137
  ```
93
138
 
94
- Or use flags:
139
+ #### End
140
+
141
+ <p align="center">
142
+ <img src="https://cdn.activitysmith.com/features/progress-live-activity-end.png" alt="Progress end example" width="680" />
143
+ </p>
95
144
 
96
145
  ```bash
97
146
  activitysmith activity end \
98
147
  --activity-id "<activityId>" \
99
- --title "Deploy" \
100
- --subtitle "done" \
101
- --current-step 4 \
102
- --auto-dismiss-minutes 3
148
+ --content-state '{"title":"EV Charging","subtitle":"Added 200 mi range","percentage":100,"autoDismissMinutes":2}'
103
149
  ```
104
150
 
105
151
  ### Channels
@@ -113,6 +159,35 @@ activitysmith push \
113
159
  --channels "devs,ops"
114
160
  ```
115
161
 
162
+ ### Rich Push Notifications with Media
163
+
164
+ <p align="center">
165
+ <img src="https://cdn.activitysmith.com/features/rich-push-notification-with-image.png" alt="Rich push notification with image" width="680" />
166
+ </p>
167
+
168
+ ```bash
169
+ activitysmith push \
170
+ --title "Homepage ready" \
171
+ --message "Your agent finished the redesign." \
172
+ --media "https://cdn.example.com/output/homepage-v2.png" \
173
+ --redirection "https://github.com/acme/web/pull/482"
174
+ ```
175
+
176
+ Send images, videos, or audio with your push notifications, press and hold to preview media directly from the notification, then tap through to open the linked content.
177
+
178
+ <p align="center">
179
+ <img src="https://cdn.activitysmith.com/features/rich-push-notification-with-audio.png" alt="Rich push notification with audio" width="680" />
180
+ </p>
181
+
182
+ What will work:
183
+
184
+ - direct image URL: `.jpg`, `.png`, `.gif`, etc.
185
+ - direct audio file URL: `.mp3`, `.m4a`, etc.
186
+ - direct video file URL: `.mp4`, `.mov`, etc.
187
+ - URL that responds with a proper media `Content-Type`, even if the path has no extension
188
+
189
+ `--media` can be combined with `--redirection`, but not with `--actions` or `--actions-file`.
190
+
116
191
  ### Push Notification Redirection and Actions
117
192
 
118
193
  Push notification redirection and actions are optional and can be used to redirect the user to a specific URL when they tap the notification or to trigger a specific action when they long-press the notification.
@@ -162,6 +237,9 @@ Or use flags to build the payload:
162
237
  - `--type <type>`
163
238
  - `--number-of-steps <number>`
164
239
  - `--current-step <number>`
240
+ - `--percentage <number>`
241
+ - `--value <number>`
242
+ - `--upper-limit <number>`
165
243
  - `--color <color>`
166
244
  - `--step-color <color>`
167
245
  - `--auto-dismiss-minutes <number>`
@@ -172,9 +250,9 @@ Targeting options:
172
250
 
173
251
  Required fields:
174
252
 
175
- - `activity start`: `title`, `numberOfSteps`, `currentStep`, `type`
176
- - `activity update`: `title`, `currentStep`
177
- - `activity end`: `title`, `currentStep`
253
+ - `activity start`: `--title`, `--type`, plus either `--number-of-steps` and `--current-step`, or `--percentage`, or `--value` with `--upper-limit`
254
+ - `activity update`: `--title`, plus either `--current-step`, or `--percentage`, or `--value` with `--upper-limit`
255
+ - `activity end`: `--title`, plus either `--current-step`, or `--percentage`, or `--value` with `--upper-limit`
178
256
 
179
257
  ## Output
180
258
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "activitysmith-cli",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
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",
@@ -34,13 +34,13 @@
34
34
  "src"
35
35
  ],
36
36
  "engines": {
37
- "node": ">=18"
37
+ "node": ">=24"
38
38
  },
39
39
  "scripts": {
40
40
  "lint": "node --check src/cli.js"
41
41
  },
42
42
  "dependencies": {
43
- "activitysmith": "^0.1.5",
43
+ "activitysmith": "^0.1.8",
44
44
  "commander": "^12.1.0"
45
45
  }
46
46
  }
package/src/cli.js CHANGED
@@ -29,6 +29,14 @@ const parseIntegerOption = (label) => (value) => {
29
29
  return parsed;
30
30
  };
31
31
 
32
+ const parseNumberOption = (label) => (value) => {
33
+ const parsed = Number(value);
34
+ if (!Number.isFinite(parsed)) {
35
+ throw new InvalidArgumentError(`${label} must be a number`);
36
+ }
37
+ return parsed;
38
+ };
39
+
32
40
  const parseChannelsOption = (value) => {
33
41
  if (typeof value !== "string") {
34
42
  throw new InvalidArgumentError("channels must be a comma-separated string");
@@ -82,6 +90,21 @@ const addContentStateOptions = (command, { includeAutoDismiss } = {}) => {
82
90
  "Content state current step",
83
91
  parseIntegerOption("current-step")
84
92
  )
93
+ .option(
94
+ "--percentage <number>",
95
+ "Content state percentage",
96
+ parseNumberOption("percentage")
97
+ )
98
+ .option(
99
+ "--value <number>",
100
+ "Content state value",
101
+ parseNumberOption("value")
102
+ )
103
+ .option(
104
+ "--upper-limit <number>",
105
+ "Content state upper limit",
106
+ parseNumberOption("upper-limit")
107
+ )
85
108
  .option("--color <color>", "Content state color")
86
109
  .option("--step-color <color>", "Content state step color");
87
110
 
@@ -176,6 +199,132 @@ const readJsonArrayFile = async (filePath, label) => {
176
199
  return parseJsonArrayString(text, label);
177
200
  };
178
201
 
202
+ const isNonEmptyString = (value) =>
203
+ typeof value === "string" && value.trim().length > 0;
204
+
205
+ const hasOwn = (object, key) =>
206
+ Object.prototype.hasOwnProperty.call(object, key);
207
+
208
+ const validateContentState = (contentState, mode) => {
209
+ const normalizedType =
210
+ typeof contentState.type === "string" ? contentState.type.trim() : undefined;
211
+
212
+ if (!isNonEmptyString(contentState.title)) {
213
+ throw new Error("contentState.title is required");
214
+ }
215
+
216
+ if (
217
+ normalizedType !== undefined &&
218
+ normalizedType !== "segmented_progress" &&
219
+ normalizedType !== "progress"
220
+ ) {
221
+ throw new Error(
222
+ "contentState.type must be one of: segmented_progress, progress"
223
+ );
224
+ }
225
+
226
+ const hasNumberOfSteps = hasOwn(contentState, "numberOfSteps");
227
+ const hasCurrentStep = hasOwn(contentState, "currentStep");
228
+ const hasPercentage = hasOwn(contentState, "percentage");
229
+ const hasValue = hasOwn(contentState, "value");
230
+ const hasUpperLimit = hasOwn(contentState, "upperLimit");
231
+ const hasStepColor = hasOwn(contentState, "stepColor");
232
+
233
+ if (hasValue !== hasUpperLimit) {
234
+ throw new Error(
235
+ "contentState.value and contentState.upperLimit must be provided together"
236
+ );
237
+ }
238
+
239
+ if (hasNumberOfSteps && contentState.numberOfSteps < 1) {
240
+ throw new Error("contentState.numberOfSteps must be at least 1");
241
+ }
242
+
243
+ if (hasCurrentStep && contentState.currentStep < 1) {
244
+ throw new Error("contentState.currentStep must be at least 1");
245
+ }
246
+
247
+ if (
248
+ hasPercentage &&
249
+ (contentState.percentage < 0 || contentState.percentage > 100)
250
+ ) {
251
+ throw new Error("contentState.percentage must be between 0 and 100");
252
+ }
253
+
254
+ if (hasUpperLimit && contentState.upperLimit <= 0) {
255
+ throw new Error("contentState.upperLimit must be greater than 0");
256
+ }
257
+
258
+ const hasSegmentedFields = hasNumberOfSteps || hasCurrentStep || hasStepColor;
259
+ const hasProgressFields = hasPercentage || hasValue || hasUpperLimit;
260
+
261
+ if (hasSegmentedFields && hasProgressFields) {
262
+ throw new Error(
263
+ "Do not mix segmented_progress fields with progress fields in the same contentState"
264
+ );
265
+ }
266
+
267
+ const effectiveType = normalizedType;
268
+
269
+ if (mode === "start") {
270
+ if (!effectiveType) {
271
+ throw new Error("contentState.type is required for activity start");
272
+ }
273
+
274
+ if (effectiveType === "segmented_progress") {
275
+ if (!hasNumberOfSteps || !hasCurrentStep) {
276
+ throw new Error(
277
+ "segmented_progress start requires contentState.numberOfSteps and contentState.currentStep"
278
+ );
279
+ }
280
+ return;
281
+ }
282
+
283
+ if (!hasPercentage && !hasValue) {
284
+ throw new Error(
285
+ "progress start requires contentState.percentage, or contentState.value with contentState.upperLimit"
286
+ );
287
+ }
288
+ return;
289
+ }
290
+
291
+ if (effectiveType === "segmented_progress") {
292
+ if (!hasCurrentStep) {
293
+ throw new Error(
294
+ `segmented_progress ${mode} requires contentState.currentStep`
295
+ );
296
+ }
297
+ return;
298
+ }
299
+
300
+ if (effectiveType === "progress") {
301
+ if (!hasPercentage && !hasValue) {
302
+ throw new Error(
303
+ `progress ${mode} requires contentState.percentage, or contentState.value with contentState.upperLimit`
304
+ );
305
+ }
306
+ return;
307
+ }
308
+
309
+ if (!hasSegmentedFields && !hasProgressFields) {
310
+ throw new Error(
311
+ `contentState for activity ${mode} must include either segmented_progress fields or progress fields`
312
+ );
313
+ }
314
+
315
+ if (hasSegmentedFields && !hasCurrentStep) {
316
+ throw new Error(
317
+ `segmented_progress ${mode} requires contentState.currentStep`
318
+ );
319
+ }
320
+
321
+ if (hasProgressFields && !hasPercentage && !hasValue) {
322
+ throw new Error(
323
+ `progress ${mode} requires contentState.percentage, or contentState.value with contentState.upperLimit`
324
+ );
325
+ }
326
+ };
327
+
179
328
  const parsePushAction = (value, index) => {
180
329
  const label = `actions[${index}]`;
181
330
  assertPlainObject(value, label);
@@ -251,6 +400,16 @@ const loadPushActions = async (options) => {
251
400
  return actions.map(parsePushAction);
252
401
  };
253
402
 
403
+ const validatePushMediaOptions = ({ media, actions }) => {
404
+ if (media === undefined || actions === undefined) {
405
+ return;
406
+ }
407
+
408
+ if (actions.length > 0) {
409
+ throw new Error("media cannot be combined with actions");
410
+ }
411
+ };
412
+
254
413
  const buildContentStateFromOptions = (options) => {
255
414
  const contentState = {};
256
415
 
@@ -274,6 +433,18 @@ const buildContentStateFromOptions = (options) => {
274
433
  contentState.currentStep = options.currentStep;
275
434
  }
276
435
 
436
+ if (options.percentage !== undefined) {
437
+ contentState.percentage = options.percentage;
438
+ }
439
+
440
+ if (options.value !== undefined) {
441
+ contentState.value = options.value;
442
+ }
443
+
444
+ if (options.upperLimit !== undefined) {
445
+ contentState.upperLimit = options.upperLimit;
446
+ }
447
+
277
448
  if (options.color !== undefined) {
278
449
  contentState.color = options.color;
279
450
  }
@@ -293,6 +464,7 @@ const toApiContentState = (contentState) => {
293
464
  const keyMap = {
294
465
  numberOfSteps: "number_of_steps",
295
466
  currentStep: "current_step",
467
+ upperLimit: "upper_limit",
296
468
  stepColor: "step_color",
297
469
  autoDismissMinutes: "auto_dismiss_minutes",
298
470
  };
@@ -338,7 +510,7 @@ const toApiLiveActivityEndRequest = (activityId, contentState) => ({
338
510
  content_state: toApiContentState(contentState),
339
511
  });
340
512
 
341
- const loadContentState = async (options) => {
513
+ const loadContentState = async (options, mode) => {
342
514
  let contentState = {};
343
515
 
344
516
  if (options.contentStateFile) {
@@ -366,6 +538,8 @@ const loadContentState = async (options) => {
366
538
  );
367
539
  }
368
540
 
541
+ validateContentState(contentState, mode);
542
+
369
543
  return contentState;
370
544
  };
371
545
 
@@ -488,6 +662,10 @@ program
488
662
  .requiredOption("--title <title>", "Push title")
489
663
  .option("--message <message>", "Push message")
490
664
  .option("--subtitle <subtitle>", "Push subtitle")
665
+ .option(
666
+ "--media <url>",
667
+ "HTTPS URL for image, audio, or video shown when the notification is expanded"
668
+ )
491
669
  .option("--redirection <url>", "HTTPS URL opened when notification is tapped")
492
670
  .option("--actions <json>", "Actions JSON array (max 4)")
493
671
  .option("--actions-file <path>", "Path to actions JSON array file")
@@ -503,12 +681,20 @@ program
503
681
  const apiKey = requireApiKey(globalOptions);
504
682
  const client = createClient(apiKey);
505
683
  const actions = await loadPushActions(options);
684
+ validatePushMediaOptions({
685
+ media: options.media,
686
+ actions,
687
+ });
506
688
 
507
689
  const pushNotificationRequest = withTargetChannels(
508
690
  {
509
691
  title: options.title,
510
692
  message: options.message,
511
693
  subtitle: options.subtitle,
694
+ media:
695
+ options.media !== undefined
696
+ ? normalizeHttpsUrl(options.media, "media")
697
+ : undefined,
512
698
  redirection:
513
699
  options.redirection !== undefined
514
700
  ? normalizeHttpsUrl(options.redirection, "redirection")
@@ -556,7 +742,7 @@ addContentStateOptions(
556
742
  try {
557
743
  const apiKey = requireApiKey(globalOptions);
558
744
  const client = createClient(apiKey);
559
- const contentState = await loadContentState(options);
745
+ const contentState = await loadContentState(options, "start");
560
746
 
561
747
  const response = await client.liveActivities.startLiveActivity({
562
748
  liveActivityStartRequest: withTargetChannels(
@@ -587,7 +773,7 @@ addContentStateOptions(
587
773
  try {
588
774
  const apiKey = requireApiKey(globalOptions);
589
775
  const client = createClient(apiKey);
590
- const contentState = await loadContentState(options);
776
+ const contentState = await loadContentState(options, "update");
591
777
 
592
778
  const response = await client.liveActivities.updateLiveActivity({
593
779
  liveActivityUpdateRequest: toApiLiveActivityUpdateRequest(
@@ -617,7 +803,7 @@ addContentStateOptions(
617
803
  try {
618
804
  const apiKey = requireApiKey(globalOptions);
619
805
  const client = createClient(apiKey);
620
- const contentState = await loadContentState(options);
806
+ const contentState = await loadContentState(options, "end");
621
807
 
622
808
  const response = await client.liveActivities.endLiveActivity({
623
809
  liveActivityEndRequest: toApiLiveActivityEndRequest(