activitysmith 1.9.0 → 1.11.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.
package/README.md CHANGED
@@ -1,49 +1,22 @@
1
- # ActivitySmith Node SDK
1
+ # ActivitySmith Node.js SDK
2
2
 
3
- The ActivitySmith Node SDK provides convenient access to the ActivitySmith API from server-side JavaScript and TypeScript applications.
4
-
5
- ## Documentation
6
-
7
- See [API reference](https://activitysmith.com/docs/api-reference/introduction)
8
-
9
- ## Table of Contents
10
-
11
- - [Installation](#installation)
12
- - [Setup](#setup)
13
- - [Push Notifications](#push-notifications)
14
- - [Send a Push Notification](#send-a-push-notification)
15
- - [Rich Push Notifications with Media](#rich-push-notifications-with-media)
16
- - [Actionable Push Notifications](#actionable-push-notifications)
17
- - [Live Activities](#live-activities)
18
- - [Start & Update Live Activity](#start--update-live-activity)
19
- - [End Live Activity](#end-live-activity)
20
- - [Live Activity Action](#live-activity-action)
21
- - [Icons and Badges](#icons-and-badges)
22
- - [Live Activity Colors](#live-activity-colors)
23
- - [Widgets](#widgets)
24
- - [App Icon Badge Count](#app-icon-badge-count)
25
- - [Channels](#channels)
3
+ [Documentation](https://activitysmith.com/docs/sdks/node)
26
4
 
27
5
  ## Installation
28
6
 
29
- ```sh
7
+ Install the ActivitySmith Node.js SDK with npm:
8
+
9
+ ```bash
30
10
  npm install activitysmith
31
11
  ```
32
12
 
33
- ## Setup
34
-
35
- ```ts
36
- import ActivitySmith from "activitysmith";
37
-
38
- const activitysmith = new ActivitySmith({
39
- apiKey: process.env.ACTIVITYSMITH_API_KEY,
40
- });
41
- ```
13
+ ## Quickstart
42
14
 
43
- CommonJS:
15
+ 1. [Create an API key](https://activitysmith.com/app/keys)
16
+ 2. Set `ACTIVITYSMITH_API_KEY` or pass `apiKey` when creating the client.
44
17
 
45
18
  ```js
46
- const ActivitySmith = require("activitysmith");
19
+ import ActivitySmith from "activitysmith";
47
20
 
48
21
  const activitysmith = new ActivitySmith({
49
22
  apiKey: process.env.ACTIVITYSMITH_API_KEY,
@@ -54,11 +27,11 @@ const activitysmith = new ActivitySmith({
54
27
 
55
28
  ### Send a Push Notification
56
29
 
57
- <p align="center">
58
- <img src="https://cdn.activitysmith.com/features/new-subscription-push-notification.png" alt="Push notification example" width="680" />
59
- </p>
30
+ Send an immediate notification for a completed task or event.
60
31
 
61
- ```ts
32
+ ![Push Notification example for a new subscription event](https://cdn.activitysmith.com/features/new-subscription-push-notification.png)
33
+
34
+ ```js
62
35
  await activitysmith.notifications.send({
63
36
  title: "New subscription 💸",
64
37
  message: "Customer upgraded to Pro plan",
@@ -67,24 +40,19 @@ await activitysmith.notifications.send({
67
40
 
68
41
  ### Rich Push Notifications with Media
69
42
 
70
- <p align="center">
71
- <img src="https://cdn.activitysmith.com/features/rich-push-notification-with-image.png" alt="Rich push notification with image" width="680" />
72
- </p>
43
+ ![Rich Push Notification with image](https://cdn.activitysmith.com/features/rich-push-notification-with-image.png)
73
44
 
74
- ```ts
45
+ ```js
75
46
  await activitysmith.notifications.send({
76
47
  title: "Homepage ready",
77
48
  message: "Your agent finished the redesign.",
78
49
  media: "https://cdn.example.com/output/homepage-v2.png",
79
- redirection: "https://github.com/acme/web/pull/482",
80
50
  });
81
51
  ```
82
52
 
83
- 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.
53
+ Attach images, videos, or audio to your Push Notifications. Press and hold the notification to preview the media.
84
54
 
85
- <p align="center">
86
- <img src="https://cdn.activitysmith.com/features/rich-push-notification-with-audio.png" alt="Rich push notification with audio" width="680" />
87
- </p>
55
+ ![Rich Push Notification with audio](https://cdn.activitysmith.com/features/rich-push-notification-with-audio.png)
88
56
 
89
57
  What will work:
90
58
 
@@ -93,23 +61,51 @@ What will work:
93
61
  - direct video file URL: `.mp4`, `.mov`, etc.
94
62
  - URL that responds with a proper media `Content-Type`, even if the path has no extension
95
63
 
64
+ `media` cannot be combined with `actions`.
65
+
66
+ ### Push Notifications with Redirection
67
+
68
+ Open a web page, run an iOS Shortcut, or open an app when someone taps the notification. `redirection` supports:
69
+
70
+ - **HTTP/HTTPS:** Web pages, e.g. `https://example.com`
71
+ - **Shortcuts:** Run Jarvis with `shortcuts://run-shortcut?name=Jarvis` <!-- full-width -->
72
+ - **App deep links:** Installed apps or specific content within them
73
+ - **Spotify:** A track, e.g. `spotify:track:6rqhFgbbKwnb9MLmUQDhG6`
74
+ - **Termius:** `termius://` to open the app
75
+ - **Claude:** `claude://code` to open the Code tab
76
+ - **ChatGPT:** `chatgpt://` to open the app <!-- Verify ChatGPT URL scheme on iOS before publishing -->
77
+
78
+ ```js
79
+ await activitysmith.notifications.send({
80
+ title: "Homepage ready",
81
+ message: "Your agent finished the redesign.",
82
+ redirection: "https://github.com/acme/web/pull/482",
83
+ });
84
+ ```
85
+
96
86
  ### Actionable Push Notifications
97
87
 
98
- <p align="center">
99
- <img src="https://cdn.activitysmith.com/features/actionable-push-notifications-2.png" alt="Actionable push notification example" width="680" />
100
- </p>
88
+ ![Actionable Push Notification with redirection and actions](https://cdn.activitysmith.com/features/actionable-push-notifications-2.png)
101
89
 
102
- Push notification `redirection` and `actions` are optional. Use them to open HTTPS URLs, run a specific iPhone Shortcut with `shortcuts://run-shortcut?name=...`, or trigger backend webhook workflows.
103
- Webhooks are executed by the ActivitySmith backend.
90
+ `open_url` actions open a web page, run an iOS Shortcut, or open an app when someone taps the button. Supported links:
104
91
 
105
- ```ts
92
+ - **HTTP/HTTPS:** Web pages, e.g. `https://example.com`
93
+ - **Shortcuts:** Run Jarvis with `shortcuts://run-shortcut?name=Jarvis` <!-- full-width -->
94
+ - **App deep links:** Installed apps or specific content within them
95
+ - **Spotify:** A track, e.g. `spotify:track:6rqhFgbbKwnb9MLmUQDhG6`
96
+ - **Termius:** `termius://` to open the app
97
+ - **Claude:** `claude://code` to open the Code tab
98
+ - **ChatGPT:** `chatgpt://` to open the app <!-- Verify ChatGPT URL scheme on iOS before publishing -->
99
+
100
+ Webhooks are executed by the ActivitySmith backend and must use HTTPS.
101
+
102
+ ```js
106
103
  await activitysmith.notifications.send({
107
104
  title: "New subscription 💸",
108
105
  message: "Customer upgraded to Pro plan",
109
- redirection: "https://crm.example.com/customers/cus_9f3a1d", // Optional
110
106
  actions: [
111
107
  {
112
- title: "Open CRM Profile",
108
+ title: "Open CRM",
113
109
  type: "open_url",
114
110
  url: "https://crm.example.com/customers/cus_9f3a1d",
115
111
  },
@@ -128,20 +124,37 @@ await activitysmith.notifications.send({
128
124
  plan: "pro",
129
125
  },
130
126
  },
131
- ], // Optional (max 4)
127
+ ],
132
128
  });
133
129
  ```
134
130
 
135
131
  ## Live Activities
136
132
 
137
- There are six types of Live Activities:
133
+ Choose the Live Activity type that matches what you want to show:
134
+
135
+ ![Stats Live Activity with six labeled sales metrics](https://cdn.activitysmith.com/features/stats-live-activity.png)
136
+
137
+ **Stats**: Show up to 8 labeled values on your Lock Screen, from revenue and orders to uptime and conversion.
138
+
139
+ ![Metrics Live Activity with CPU and memory values](https://cdn.activitysmith.com/features/metrics-live-activity-start.png)
140
+
141
+ **Metrics**: Track two related values with segmented bars, such as CPU and memory.
142
+
143
+ ![Segmented Progress Live Activity showing a workflow step](https://cdn.activitysmith.com/features/update-live-activity.png)
144
+
145
+ **Segmented Progress**: Show progress through a known set of steps, like build, test, deploy, and verify.
138
146
 
139
- - `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
140
- - `metrics`: best for live percentage values that change often, like server CPU, memory usage, disk usage, or error rate
141
- - `segmented_progress`: best for anything that moves through clear stages, like deployments, onboarding flows, backups, ETL pipelines, migrations, and AI agent runs
142
- - `progress`: best for tracking real-time progress with percentage, like tasks, backups, migrations, syncs, or uploads
143
- - `alert`: best for status updates, such as feature adoption, reactivation, onboarding blockers, incidents, escalations, and other operational states
144
- - `timer`: best for countdowns and elapsed runtime, like benchmark runs, uploads, backups, transcodes, and long-running jobs
147
+ ![Progress Live Activity showing percentage completion](https://cdn.activitysmith.com/features/progress-live-activity.png)
148
+
149
+ **Progress**: Show percentage progress for jobs that move continuously toward completion.
150
+
151
+ ![Alert Live Activity showing a customer reactivation update](https://cdn.activitysmith.com/features/alert-live-activity.png)
152
+
153
+ **Alert**: Show status updates with a clear message, badge, and icon. When you add an action button, `color` controls the button tint.
154
+
155
+ ![Timer Live Activity showing a benchmark run countdown](https://cdn.activitysmith.com/features/timer-live-activity.png)
156
+
157
+ **Timer**: Count down from a duration, or count up from 00:00 while a job runs.
145
158
 
146
159
  ### Start & Update Live Activity
147
160
 
@@ -149,9 +162,7 @@ Use a stable `streamKey` to identify the metric, job, deployment, or system you
149
162
 
150
163
  #### Stats
151
164
 
152
- <p align="center">
153
- <img src="https://cdn.activitysmith.com/features/stats-live-activity.png" alt="Stats Live Activity stream example" width="680" />
154
- </p>
165
+ ![Stats Live Activity stream example](https://cdn.activitysmith.com/features/stats-live-activity.png)
155
166
 
156
167
  ```ts
157
168
  await activitysmith.liveActivities.stream("sales-hourly", {
@@ -173,9 +184,7 @@ await activitysmith.liveActivities.stream("sales-hourly", {
173
184
 
174
185
  #### Metrics
175
186
 
176
- <p align="center">
177
- <img src="https://cdn.activitysmith.com/features/metrics-live-activity-start.png" alt="Metrics Live Activity stream example" width="680" />
178
- </p>
187
+ ![Metrics Live Activity stream example](https://cdn.activitysmith.com/features/metrics-live-activity-start.png)
179
188
 
180
189
  ```ts
181
190
  await activitysmith.liveActivities.stream("prod-web-1", {
@@ -193,9 +202,7 @@ await activitysmith.liveActivities.stream("prod-web-1", {
193
202
 
194
203
  #### Segmented Progress
195
204
 
196
- <p align="center">
197
- <img src="https://cdn.activitysmith.com/features/update-live-activity.png" alt="Segmented Progress Live Activity stream example" width="680" />
198
- </p>
205
+ ![Segmented Progress Live Activity stream example](https://cdn.activitysmith.com/features/update-live-activity.png)
199
206
 
200
207
  ```ts
201
208
  await activitysmith.liveActivities.stream("nightly-backup", {
@@ -211,9 +218,7 @@ await activitysmith.liveActivities.stream("nightly-backup", {
211
218
 
212
219
  #### Progress
213
220
 
214
- <p align="center">
215
- <img src="https://cdn.activitysmith.com/features/progress-live-activity.png" alt="Progress Live Activity stream example" width="680" />
216
- </p>
221
+ ![Progress Live Activity stream example](https://cdn.activitysmith.com/features/progress-live-activity.png)
217
222
 
218
223
  ```ts
219
224
  await activitysmith.liveActivities.stream("search-reindex", {
@@ -228,9 +233,7 @@ await activitysmith.liveActivities.stream("search-reindex", {
228
233
 
229
234
  #### Alert
230
235
 
231
- <p align="center">
232
- <img src="https://cdn.activitysmith.com/features/alert-live-activity.png" alt="Alert Live Activity stream example" width="680" />
233
- </p>
236
+ ![Alert Live Activity stream example](https://cdn.activitysmith.com/features/alert-live-activity.png)
234
237
 
235
238
  ```ts
236
239
  await activitysmith.liveActivities.stream("customer-ops", {
@@ -246,9 +249,7 @@ await activitysmith.liveActivities.stream("customer-ops", {
246
249
 
247
250
  #### Timer
248
251
 
249
- <p align="center">
250
- <img src="https://cdn.activitysmith.com/features/timer-live-activity.png" alt="Timer Live Activity showing a benchmark run countdown" width="680" />
251
- </p>
252
+ ![Timer Live Activity stream example](https://cdn.activitysmith.com/features/timer-live-activity.png)
252
253
 
253
254
  ```ts
254
255
  await activitysmith.liveActivities.stream("benchmark-run", {
@@ -268,7 +269,7 @@ To start at 00:00 and count up, set `counts_down: false` and leave out `duration
268
269
 
269
270
  ### End Live Activity
270
271
 
271
- Call `endStream(...)` with the same `streamKey` 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 `auto_dismiss_minutes` to choose a different dismissal time, including `0` for immediate dismissal.
272
+ Call `endStream(...)` with the same `streamKey` to dismiss the Live Activity. You can include final values before it is removed. Set `auto_dismiss_seconds` to dismiss it after a delay in seconds, or `auto_dismiss_minutes` for minutes. Use `0` for immediate dismissal. Seconds take precedence if both are set.
272
273
 
273
274
  ```ts
274
275
  await activitysmith.liveActivities.endStream("prod-web-1", {
@@ -280,25 +281,82 @@ await activitysmith.liveActivities.endStream("prod-web-1", {
280
281
  { label: "CPU", value: 7, unit: "%" },
281
282
  { label: "MEM", value: 38, unit: "%" },
282
283
  ],
283
- auto_dismiss_minutes: 2,
284
+ auto_dismiss_seconds: 30,
284
285
  },
285
286
  });
286
287
  ```
287
288
 
289
+ ### Icons and Badges
290
+
291
+ Add more context to Live Activities with icons and badges.
292
+
293
+ #### Icon
294
+
295
+ Supported Live Activity types: `stats`, `metrics`, `progress`, `segmented_progress`, `alert`, and `timer`.
296
+
297
+ ![Metrics Live Activity with an SF Symbol icon on the iPhone Lock Screen](https://cdn.activitysmith.com/features/metrics-live-activity-with-icon.png)
298
+
299
+ ```ts
300
+ await activitysmith.liveActivities.stream("prod-web-1", {
301
+ content_state: ActivitySmith.contentState({
302
+ title: "Server Health",
303
+ subtitle: "prod-web-1",
304
+ type: "metrics",
305
+ icon: ActivitySmith.alertIcon("server.rack", { color: "blue" }),
306
+ metrics: [
307
+ { label: "CPU", value: 18, unit: "%" },
308
+ { label: "MEM", value: 42, unit: "%" },
309
+ ],
310
+ }),
311
+ });
312
+ ```
313
+
314
+ The `icon.symbol` value is an Apple SF Symbol name. Browse the catalog with one of these tools:
315
+
316
+ - [ActivitySmith app](https://apps.apple.com/us/app/activitysmith/id6752254835) - Open Settings -> SF Symbols to browse 45 hand-picked icons ready to use
317
+ - [SF Symbols](https://developer.apple.com/sf-symbols/) - Apple's official macOS app
318
+ - [Interactful](https://apps.apple.com/app/interactful/id1528095640) - free third-party iOS app listing all SF Symbols under Foundations -> Iconography
319
+
320
+ #### Badge
321
+
322
+ Badges are supported by `alert`, `progress`, and `segmented_progress` Live Activities.
323
+
324
+ ![Progress Live Activity with a badge on the iPhone Lock Screen](https://cdn.activitysmith.com/features/progress-live-activity-with-badge.png)
325
+
326
+ ```ts
327
+ await activitysmith.liveActivities.stream("nightly-database-backup", {
328
+ content_state: ActivitySmith.contentState({
329
+ title: "Nightly Database Backup",
330
+ subtitle: "verify restore",
331
+ type: "progress",
332
+ badge: ActivitySmith.alertBadge("S3", { color: "cyan" }),
333
+ percentage: 62,
334
+ }),
335
+ });
336
+ ```
337
+
338
+ ### Live Activity Colors
339
+
340
+ Choose from these colors for the Live Activity accent, including progress bars and action buttons, or apply them to an individual icon or badge:
341
+
342
+ `lime`, `green`, `cyan`, `blue`, `purple`, `magenta`, `red`, `orange`, `yellow`, `gray`
343
+
288
344
  ### Live Activity Action
289
345
 
290
- Live Activities can include an action button.
346
+ ![Metrics Live Activity with action](https://cdn.activitysmith.com/features/metrics-live-activity-action.png)
291
347
 
292
- - `open_url`: open an HTTPS URL.
293
- - `open_url` with a `shortcuts://` URL: run an Apple Shortcut, for example to open an app.
294
- - `webhook`: trigger a backend GET/POST workflow.
348
+ Live Activities can include an action button.
295
349
 
296
- <p align="center">
297
- <img src="https://cdn.activitysmith.com/features/metrics-live-activity-action.png" alt="Live Activity with action button" width="680" />
298
- </p>
350
+ - `open_url`: Open a web page or run an iOS Shortcut
351
+ - `webhook`: Trigger a backend GET/POST workflow
299
352
 
300
353
  #### Open URL action
301
354
 
355
+ Open a web page or run an iOS Shortcut when someone taps the button. Supported links:
356
+
357
+ - **HTTP/HTTPS:** Web pages, e.g. `https://example.com`
358
+ - **Shortcuts:** Run Jarvis with `shortcuts://run-shortcut?name=Jarvis` <!-- full-width -->
359
+
302
360
  ```ts
303
361
  await activitysmith.liveActivities.stream("prod-web-1", {
304
362
  content_state: {
@@ -313,7 +371,7 @@ await activitysmith.liveActivities.stream("prod-web-1", {
313
371
  action: {
314
372
  title: "Dashboard",
315
373
  type: "open_url",
316
- url: "https://ops.example.com/servers/prod-web-1",
374
+ url: "https://status.example.com/servers/prod-web-1",
317
375
  },
318
376
  });
319
377
  ```
@@ -321,13 +379,15 @@ await activitysmith.liveActivities.stream("prod-web-1", {
321
379
  #### Apple Shortcut action
322
380
 
323
381
  ```ts
324
- await activitysmith.liveActivities.stream("deploy-payments-api", {
382
+ await activitysmith.liveActivities.stream("prod-web-1", {
325
383
  content_state: {
326
- title: "Deploying payments-api",
327
- subtitle: "Running database migrations",
328
- type: "segmented_progress",
329
- number_of_steps: 5,
330
- current_step: 3,
384
+ title: "Server Health",
385
+ subtitle: "prod-web-1",
386
+ type: "metrics",
387
+ metrics: [
388
+ { label: "CPU", value: 76, unit: "%" },
389
+ { label: "MEM", value: 52, unit: "%" },
390
+ ],
331
391
  },
332
392
  action: {
333
393
  title: "Chat with Jarvis",
@@ -363,9 +423,7 @@ await activitysmith.liveActivities.stream("search-reindex", {
363
423
 
364
424
  #### Secondary action
365
425
 
366
- <p align="center">
367
- <img src="https://cdn.activitysmith.com/features/live-activity-secondary-action.png" alt="Alert Live Activity with primary and secondary action buttons" width="680" />
368
- </p>
426
+ ![Alert Live Activity with primary and secondary action buttons](https://cdn.activitysmith.com/features/live-activity-secondary-action.png)
369
427
 
370
428
  Use `secondary_action` when you want a second button beside the primary `action`.
371
429
 
@@ -410,140 +468,120 @@ await activitysmith.liveActivities.stream("agent-approval", {
410
468
  });
411
469
  ```
412
470
 
413
- ### Icons and Badges
471
+ ## Lock Screen Widgets
414
472
 
415
- Add more context to Live Activities with icons and badges.
473
+ ![Lock screen widgets](https://cdn.activitysmith.com/features/lock-screen-widgets.png)
416
474
 
417
- #### Icon
475
+ ActivitySmith lets you display any value on your Lock Screen with widgets - SaaS metrics, revenue, signups, uptime, habits, or anything else you want to track. Create a metric in the [web app](https://activitysmith.com/app/widgets), then update the metric value using our API, add a widget to your lock screen and it will fetch the latest update automatically.
418
476
 
419
- Supported Live Activity types: `stats`, `metrics`, `progress`, `segmented_progress`, `alert`, and `timer`.
477
+ ![Create widget metric](https://cdn.activitysmith.com/features/create-widget-metric.png)
420
478
 
421
- <p align="center">
422
- <img src="https://cdn.activitysmith.com/features/metrics-live-activity-with-icon.png" alt="Metrics Live Activity with an SF Symbol icon on the iPhone Lock Screen" width="680" />
423
- </p>
479
+ Use the metric key to update its value.
424
480
 
425
481
  ```ts
426
- await activitysmith.liveActivities.stream("prod-web-1", {
427
- content_state: ActivitySmith.contentState({
428
- title: "Server Health",
429
- subtitle: "prod-web-1",
430
- type: "metrics",
431
- icon: ActivitySmith.alertIcon("server.rack", { color: "blue" }),
432
- metrics: [
433
- { label: "CPU", value: 18, unit: "%" },
434
- { label: "MEM", value: 42, unit: "%" },
435
- ],
436
- }),
437
- });
482
+ await activitysmith.metrics.update("deploy.success_rate", 99.9);
438
483
  ```
439
484
 
440
- The `icon.symbol` value is an Apple SF Symbol name. Browse the catalog with one of these tools:
441
-
442
- - [ActivitySmith app](https://apps.apple.com/us/app/activitysmith/id6752254835) - Open Settings -> SF Symbols to browse 45 hand-picked icons ready to use
443
- - [SF Symbols](https://developer.apple.com/sf-symbols/) - Apple's official macOS app
444
- - [Interactful](https://apps.apple.com/app/interactful/id1528095640) - free third-party iOS app listing all SF Symbols under Foundations -> Iconography
445
-
446
- #### Badge
447
-
448
- Badges are supported by `alert`, `progress`, and `segmented_progress` Live Activities.
449
-
450
- <p align="center">
451
- <img src="https://cdn.activitysmith.com/features/progress-live-activity-with-badge.png" alt="Progress Live Activity with a badge on the iPhone Lock Screen" width="680" />
452
- </p>
485
+ String metric values work too.
453
486
 
454
487
  ```ts
455
- await activitysmith.liveActivities.stream("nightly-database-backup", {
456
- content_state: ActivitySmith.contentState({
457
- title: "Nightly Database Backup",
458
- subtitle: "verify restore",
459
- type: "progress",
460
- badge: ActivitySmith.alertBadge("S3", { color: "cyan" }),
461
- percentage: 62,
462
- }),
463
- });
488
+ await activitysmith.metrics.update("prod.status", "healthy");
464
489
  ```
465
490
 
466
- ### Live Activity Colors
491
+ ## App Icon Badge Count
467
492
 
468
- Choose from these colors for the Live Activity accent, including progress bars and action buttons, or apply them to an individual icon or badge:
493
+ ![ActivitySmith app icon with an App Icon Badge Count](https://cdn.activitysmith.com/features/badge-count.png)
469
494
 
470
- `lime`, `green`, `cyan`, `blue`, `purple`, `magenta`, `red`, `orange`, `yellow`, `gray`
471
-
472
- ## Widgets
495
+ Show the number you care about on your ActivitySmith app icon. Track MRR, a customer count, a stock price, or any other value you want to keep in view.
473
496
 
474
- <p align="center">
475
- <img src="https://cdn.activitysmith.com/features/lock-screen-widgets.png" alt="Lock screen widgets" width="680" />
476
- </p>
497
+ ### Set or update the badge value
477
498
 
478
- ActivitySmith lets you display any value on your Lock Screen with widgets - SaaS metrics, revenue, signups, uptime, habits, or anything else you want to track. Create a metric in the <a href="https://activitysmith.com/app/widgets" target="_blank" rel="noopener noreferrer">web app</a>, then update the metric value using our API, add a widget to your lock screen and it will fetch the latest update automatically.
499
+ ```js
500
+ await activitysmith.badgeCount(8333);
501
+ ```
479
502
 
480
- <p align="center">
481
- <img src="https://cdn.activitysmith.com/features/create-widget-metric.png" alt="Create widget metric" width="680" />
482
- </p>
503
+ ### Clear the badge
483
504
 
484
- Use the metric key to update its value.
505
+ Pass `0` to clear the badge.
485
506
 
486
- ```ts
487
- await activitysmith.metrics.update("deploy.success_rate", 99.9);
507
+ ```js
508
+ await activitysmith.badgeCount(0);
488
509
  ```
489
510
 
490
- String metric values work too.
511
+ ## Metadata
491
512
 
492
- ```ts
493
- await activitysmith.metrics.update("prod.status", "healthy");
494
- ```
513
+ Metadata adds extra information to Push Notification and Live Activity details in ActivitySmith. It does not appear in the notification or Live Activity on your device.
495
514
 
496
- ## App Icon Badge Count
515
+ ```js
516
+ await activitysmith.notifications.send({
517
+ title: "New subscription 💸",
518
+ message: "Customer upgraded to Pro plan",
519
+ metadata: {
520
+ customer_id: "382",
521
+ plan: "Pro",
522
+ amount: 29,
523
+ trial: false,
524
+ },
525
+ });
497
526
 
498
- <p align="center">
499
- <img src="https://cdn.activitysmith.com/features/badge-count.png" alt="ActivitySmith app icon with an App Icon Badge Count" width="680" />
500
- </p>
527
+ await activitysmith.liveActivities.stream("customer-import", {
528
+ content_state: {
529
+ title: "Customer Import",
530
+ type: "progress",
531
+ percentage: 60,
532
+ },
533
+ metadata: {
534
+ job_id: "import-382",
535
+ records: 1200,
536
+ },
537
+ });
538
+ ```
501
539
 
502
- Show the number you care about on your ActivitySmith app icon. Track MRR, a customer count, a stock price, or any other value you want to keep in view.
540
+ Values can be strings, numbers, or booleans. Metadata supports up to 50 entries and 16 KB of JSON, with keys up to 100 characters and strings up to 4,000 characters. Nested objects, arrays, and null values are not supported.
503
541
 
504
- Set or update the badge value.
542
+ ## Tags
505
543
 
506
- ```ts
507
- await activitysmith.badgeCount(8333);
544
+ Use `tags` to organize and filter your Push Notification and Live Activity history. Tags are created automatically when you first use them.
545
+
546
+ ```js
547
+ await activitysmith.notifications.send({
548
+ title: "New subscription 💸",
549
+ message: "Customer upgraded to Pro plan",
550
+ tags: ["user:382", "billing"],
551
+ });
508
552
  ```
509
553
 
510
- To clear the badge, set its value to 0.
554
+ On Live Activity stream updates and legacy `update` or `end` calls, omit `tags` to keep existing Tags, supply a list to replace them, or pass `tags: []` to clear them.
511
555
 
512
- ```ts
513
- await activitysmith.badgeCount(0);
556
+ ```js
557
+ await activitysmith.liveActivities.update({
558
+ activity_id: "YOUR_ACTIVITY_ID",
559
+ content_state: { title: "Customer Import", percentage: 60 },
560
+ tags: [],
561
+ });
514
562
  ```
515
563
 
516
564
  ## Channels
517
565
 
518
- Use `channels` to target specific team members or devices
566
+ Use `channels` to target specific team members or devices when sending Push Notifications, Live Activities, or App Icon Badge Count updates. Omit it for account-wide delivery.
519
567
 
520
- ### Push Notifications
521
-
522
- ```ts
568
+ ```js
523
569
  await activitysmith.notifications.send({
524
570
  title: "New subscription 💸",
525
571
  message: "Customer upgraded to Pro plan",
526
572
  channels: ["sales", "customer-success"],
527
573
  });
528
- ```
529
-
530
- ### Live Activities
531
574
 
532
- ```ts
533
- await activitysmith.liveActivities.start({
575
+ await activitysmith.liveActivities.stream("nightly-backup", {
534
576
  content_state: {
535
- title: "Nightly Database Backup",
536
- subtitle: "verify restore",
537
- type: "progress",
538
- percentage: 62,
577
+ title: "Nightly database backup",
578
+ number_of_steps: 3,
579
+ current_step: 1,
580
+ type: "segmented_progress",
539
581
  },
540
- channels: ["sales", "customer-success"],
582
+ channels: ["ios-builds"],
541
583
  });
542
- ```
543
-
544
- ### App Icon Badge Count
545
584
 
546
- ```ts
547
585
  await activitysmith.badgeCount(3, {
548
586
  channels: ["sales", "customer-success"],
549
587
  });
@@ -551,24 +589,18 @@ await activitysmith.badgeCount(3, {
551
589
 
552
590
  ## Error Handling
553
591
 
554
- ```ts
592
+ SDK calls return promises, so you can wrap API calls with `try/catch`:
593
+
594
+ ```js
555
595
  try {
556
- await activitysmith.notifications.send({
557
- title: "New subscription 💸",
558
- });
596
+ await activitysmith.notifications.send({ title: "Hello" });
559
597
  } catch (error) {
560
598
  console.error(error);
561
599
  }
562
600
  ```
563
601
 
564
- ## TypeScript Support
565
-
566
- This package is written in TypeScript and ships with type definitions out of the box.
567
-
568
- ## Requirements
569
-
570
- - Node.js 18 or newer
602
+ ## Additional Resources
571
603
 
572
- ## License
604
+ ### [NPM Package](https://www.npmjs.com/package/activitysmith)
573
605
 
574
- MIT
606
+ Install the ActivitySmith Node.js SDK from npm