activitysmith-cli 0.1.6 → 0.1.7
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 +80 -31
- package/package.json +1 -1
- package/src/cli.js +168 -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
|
-
|
|
47
|
+
## Live Activities
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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.
|
|
54
62
|
|
|
55
|
-
|
|
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.
|
|
73
|
+
|
|
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 "
|
|
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
|
-
|
|
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":"
|
|
95
|
+
--content-state '{"title":"Nightly database backup","subtitle":"upload archive","numberOfSteps":4,"currentStep":2}'
|
|
74
96
|
```
|
|
75
97
|
|
|
76
|
-
|
|
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
|
|
105
|
+
activitysmith activity end \
|
|
80
106
|
--activity-id "<activityId>" \
|
|
81
|
-
--title "
|
|
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
|
-
###
|
|
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
|
|
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":"
|
|
136
|
+
--content-state '{"title":"EV Charging","subtitle":"Added 120 mi range","percentage":60}'
|
|
92
137
|
```
|
|
93
138
|
|
|
94
|
-
|
|
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 "
|
|
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
|
|
@@ -162,6 +208,9 @@ Or use flags to build the payload:
|
|
|
162
208
|
- `--type <type>`
|
|
163
209
|
- `--number-of-steps <number>`
|
|
164
210
|
- `--current-step <number>`
|
|
211
|
+
- `--percentage <number>`
|
|
212
|
+
- `--value <number>`
|
|
213
|
+
- `--upper-limit <number>`
|
|
165
214
|
- `--color <color>`
|
|
166
215
|
- `--step-color <color>`
|
|
167
216
|
- `--auto-dismiss-minutes <number>`
|
|
@@ -172,9 +221,9 @@ Targeting options:
|
|
|
172
221
|
|
|
173
222
|
Required fields:
|
|
174
223
|
|
|
175
|
-
- `activity start`:
|
|
176
|
-
- `activity update`:
|
|
177
|
-
- `activity end`:
|
|
224
|
+
- `activity start`: `--title`, `--type`, plus either `--number-of-steps` and `--current-step`, or `--percentage`, or `--value` with `--upper-limit`
|
|
225
|
+
- `activity update`: `--title`, plus either `--current-step`, or `--percentage`, or `--value` with `--upper-limit`
|
|
226
|
+
- `activity end`: `--title`, plus either `--current-step`, or `--percentage`, or `--value` with `--upper-limit`
|
|
178
227
|
|
|
179
228
|
## Output
|
|
180
229
|
|
package/package.json
CHANGED
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);
|
|
@@ -274,6 +423,18 @@ const buildContentStateFromOptions = (options) => {
|
|
|
274
423
|
contentState.currentStep = options.currentStep;
|
|
275
424
|
}
|
|
276
425
|
|
|
426
|
+
if (options.percentage !== undefined) {
|
|
427
|
+
contentState.percentage = options.percentage;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
if (options.value !== undefined) {
|
|
431
|
+
contentState.value = options.value;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
if (options.upperLimit !== undefined) {
|
|
435
|
+
contentState.upperLimit = options.upperLimit;
|
|
436
|
+
}
|
|
437
|
+
|
|
277
438
|
if (options.color !== undefined) {
|
|
278
439
|
contentState.color = options.color;
|
|
279
440
|
}
|
|
@@ -293,6 +454,7 @@ const toApiContentState = (contentState) => {
|
|
|
293
454
|
const keyMap = {
|
|
294
455
|
numberOfSteps: "number_of_steps",
|
|
295
456
|
currentStep: "current_step",
|
|
457
|
+
upperLimit: "upper_limit",
|
|
296
458
|
stepColor: "step_color",
|
|
297
459
|
autoDismissMinutes: "auto_dismiss_minutes",
|
|
298
460
|
};
|
|
@@ -338,7 +500,7 @@ const toApiLiveActivityEndRequest = (activityId, contentState) => ({
|
|
|
338
500
|
content_state: toApiContentState(contentState),
|
|
339
501
|
});
|
|
340
502
|
|
|
341
|
-
const loadContentState = async (options) => {
|
|
503
|
+
const loadContentState = async (options, mode) => {
|
|
342
504
|
let contentState = {};
|
|
343
505
|
|
|
344
506
|
if (options.contentStateFile) {
|
|
@@ -366,6 +528,8 @@ const loadContentState = async (options) => {
|
|
|
366
528
|
);
|
|
367
529
|
}
|
|
368
530
|
|
|
531
|
+
validateContentState(contentState, mode);
|
|
532
|
+
|
|
369
533
|
return contentState;
|
|
370
534
|
};
|
|
371
535
|
|
|
@@ -556,7 +720,7 @@ addContentStateOptions(
|
|
|
556
720
|
try {
|
|
557
721
|
const apiKey = requireApiKey(globalOptions);
|
|
558
722
|
const client = createClient(apiKey);
|
|
559
|
-
const contentState = await loadContentState(options);
|
|
723
|
+
const contentState = await loadContentState(options, "start");
|
|
560
724
|
|
|
561
725
|
const response = await client.liveActivities.startLiveActivity({
|
|
562
726
|
liveActivityStartRequest: withTargetChannels(
|
|
@@ -587,7 +751,7 @@ addContentStateOptions(
|
|
|
587
751
|
try {
|
|
588
752
|
const apiKey = requireApiKey(globalOptions);
|
|
589
753
|
const client = createClient(apiKey);
|
|
590
|
-
const contentState = await loadContentState(options);
|
|
754
|
+
const contentState = await loadContentState(options, "update");
|
|
591
755
|
|
|
592
756
|
const response = await client.liveActivities.updateLiveActivity({
|
|
593
757
|
liveActivityUpdateRequest: toApiLiveActivityUpdateRequest(
|
|
@@ -617,7 +781,7 @@ addContentStateOptions(
|
|
|
617
781
|
try {
|
|
618
782
|
const apiKey = requireApiKey(globalOptions);
|
|
619
783
|
const client = createClient(apiKey);
|
|
620
|
-
const contentState = await loadContentState(options);
|
|
784
|
+
const contentState = await loadContentState(options, "end");
|
|
621
785
|
|
|
622
786
|
const response = await client.liveActivities.endLiveActivity({
|
|
623
787
|
liveActivityEndRequest: toApiLiveActivityEndRequest(
|