activitysmith 1.1.0 → 1.2.1

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
@@ -6,6 +6,24 @@ The ActivitySmith Node SDK provides convenient access to the ActivitySmith API f
6
6
 
7
7
  See [API reference](https://activitysmith.com/docs/api-reference/introduction)
8
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
+ - [Simple: Let ActivitySmith manage the Live Activity for you](#simple-let-activitysmith-manage-the-live-activity-for-you)
19
+ - [Advanced: Full lifecycle control](#advanced-full-lifecycle-control)
20
+ - [Metrics Type](#metrics-type)
21
+ - [Segmented Progress Type](#segmented-progress-type)
22
+ - [Progress Type](#progress-type)
23
+ - [Live Activity Action](#live-activity-action)
24
+ - [Channels](#channels)
25
+ - [Widgets](#widgets)
26
+
9
27
  ## Installation
10
28
 
11
29
  ```sh
@@ -112,32 +130,27 @@ await activitysmith.notifications.send({
112
130
  ## Live Activities
113
131
 
114
132
  <p align="center">
115
- <img src="https://cdn.activitysmith.com/features/metrics-live-activity-action.png" alt="Live Activities example" width="680" />
133
+ <img src="https://cdn.activitysmith.com/features/metrics-live-activity-action.png" alt="Metrics Live Activity screenshot" width="680" />
116
134
  </p>
117
135
 
118
- ActivitySmith supports two ways to drive Live Activities:
136
+ There are three types of Live Activities:
119
137
 
120
- - Recommended: stream updates with `activitysmith.liveActivities.stream(...)`
121
- - Advanced: manual lifecycle control with `start`, `update`, and `end`
138
+ - `metrics`: best for live operational stats like server CPU and memory, queue depth, or replica lag
139
+ - `segmented_progress`: best for step-based workflows like deployments, backups, and ETL pipelines
140
+ - `progress`: best for continuous jobs like uploads, reindexes, and long-running migrations tracked as a percentage
122
141
 
123
- Use stream updates when you want the easiest, stateless flow. You don't need to
124
- store `activity_id` or manage lifecycle state yourself. Send the latest state
125
- for a stable `streamKey` and ActivitySmith will start or update the Live
126
- Activity for you. When the tracked process is over, call `endStream(...)`.
142
+ When working with Live Activities via our API, you have two approaches tailored to different needs. First, the stateless mode is the simplest path - one API call can initiate or update an activity, and another ends it - no state tracking on your side.
127
143
 
128
- Use the manual lifecycle methods when you need direct control over a specific
129
- Live Activity instance.
144
+ This is ideal if you want minimal complexity, perfect for automated workflows like cron jobs.
130
145
 
131
- Live Activity UI types:
146
+ In contrast, if you need precise lifecycle control, the classic approach offers distinct calls for start, updates, and end, giving you full control over the activity's state.
132
147
 
133
- - `metrics`: best for live operational stats like server CPU and memory, queue depth, or replica lag
134
- - `segmented_progress`: best for step-based workflows like deployments, backups, and ETL pipelines
135
- - `progress`: best for continuous jobs like uploads, reindexes, and long-running migrations tracked as a percentage
148
+ In the following sections, we'll break down how to implement each method so you can choose what fits your use case best.
136
149
 
137
- ### Recommended: Stream updates
150
+ ### Simple: Let ActivitySmith manage the Live Activity for you
138
151
 
139
152
  Use a stable `streamKey` to identify the system or workflow you are tracking,
140
- such as a server, deployment, build pipeline, cron job, or charging session.
153
+ such as a server, deployment, or build pipeline.
141
154
  This is especially useful for cron jobs and other scheduled tasks where you do
142
155
  not want to store `activity_id` between runs.
143
156
 
@@ -230,11 +243,9 @@ Stream responses include an `operation` field:
230
243
  - `paused`: the stream is paused, so no Live Activity was started or updated
231
244
  - `ended`: returned by `endStream(...)` after the stream is ended
232
245
 
233
- ### Advanced: Manual lifecycle control
234
-
235
- Use these methods when you want to manage the Live Activity lifecycle yourself.
246
+ ### Advanced: Full lifecycle control
236
247
 
237
- #### Shared flow
248
+ Use these methods when you want to manage the Live Activity lifecycle yourself:
238
249
 
239
250
  1. Call `activitysmith.liveActivities.start(...)`.
240
251
  2. Save the returned `activity_id`.
@@ -313,10 +324,10 @@ await activitysmith.liveActivities.end({
313
324
 
314
325
  ### Segmented Progress Type
315
326
 
316
- Use `segmented_progress` when progress is easier to follow as steps instead of a
317
- raw percentage. It fits jobs like backups, deployments, ETL pipelines, and
318
- checklists where "step 2 of 3" is more useful than "67%". `number_of_steps` is
319
- dynamic, so you can increase or decrease it later if the workflow changes.
327
+ Use `segmented_progress` for jobs and workflows that move through clear steps or
328
+ phases. It fits jobs like backups, deployments, ETL pipelines, and checklists.
329
+ `number_of_steps` is dynamic, so you can increase or decrease it later if the
330
+ workflow changes.
320
331
 
321
332
  #### Start
322
333
 
@@ -508,6 +519,30 @@ await activitysmith.notifications.send({
508
519
  });
509
520
  ```
510
521
 
522
+ ## Widgets
523
+
524
+ <p align="center">
525
+ <img src="https://cdn.activitysmith.com/features/lock-screen-widgets.png" alt="Lock screen widgets" width="680" />
526
+ </p>
527
+
528
+ 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.
529
+
530
+ <p align="center">
531
+ <img src="https://cdn.activitysmith.com/features/create-widget-metric.png" alt="Create widget metric" width="680" />
532
+ </p>
533
+
534
+ Use the metric key to update its value.
535
+
536
+ ```ts
537
+ await activitysmith.metrics.update("deploy.success_rate", 99.9);
538
+ ```
539
+
540
+ String metric values work too.
541
+
542
+ ```ts
543
+ await activitysmith.metrics.update("prod.status", "healthy");
544
+ ```
545
+
511
546
  ## Error Handling
512
547
 
513
548
  ```ts
@@ -33,12 +33,12 @@ export interface UpdateLiveActivityRequest {
33
33
  */
34
34
  export declare class LiveActivitiesApi extends runtime.BaseAPI {
35
35
  /**
36
- * Ends a Live Activity and archives its lifecycle. Supports segmented_progress, progress, metrics, and the legacy counter/timer/countdown step-based activity types. For segmented_progress activities, you can send the latest number_of_steps here if the workflow changed after start.
36
+ * Ends a Live Activity and archives its lifecycle. Supports segmented_progress, progress, and metrics activity types. For segmented_progress activities, you can send the latest number_of_steps here if the workflow changed after start.
37
37
  * End a Live Activity
38
38
  */
39
39
  endLiveActivityRaw(requestParameters: EndLiveActivityRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<LiveActivityEndResponse>>;
40
40
  /**
41
- * Ends a Live Activity and archives its lifecycle. Supports segmented_progress, progress, metrics, and the legacy counter/timer/countdown step-based activity types. For segmented_progress activities, you can send the latest number_of_steps here if the workflow changed after start.
41
+ * Ends a Live Activity and archives its lifecycle. Supports segmented_progress, progress, and metrics activity types. For segmented_progress activities, you can send the latest number_of_steps here if the workflow changed after start.
42
42
  * End a Live Activity
43
43
  */
44
44
  endLiveActivity(requestParameters: EndLiveActivityRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<LiveActivityEndResponse>;
@@ -63,22 +63,22 @@ export declare class LiveActivitiesApi extends runtime.BaseAPI {
63
63
  */
64
64
  reconcileLiveActivityStream(requestParameters: ReconcileLiveActivityStreamRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<LiveActivityStreamPutResponse>;
65
65
  /**
66
- * Starts a Live Activity on devices matched by API key scope and optional target channels. Supports segmented_progress, progress, metrics, and the legacy counter/timer/countdown step-based activity types. For segmented_progress activities, number_of_steps can be changed later during update or end calls if the workflow changes.
66
+ * Starts a Live Activity on devices matched by API key scope and optional target channels. Supports segmented_progress, progress, and metrics activity types. For segmented_progress activities, number_of_steps can be changed later during update or end calls if the workflow changes.
67
67
  * Start a Live Activity
68
68
  */
69
69
  startLiveActivityRaw(requestParameters: StartLiveActivityRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<LiveActivityStartResponse>>;
70
70
  /**
71
- * Starts a Live Activity on devices matched by API key scope and optional target channels. Supports segmented_progress, progress, metrics, and the legacy counter/timer/countdown step-based activity types. For segmented_progress activities, number_of_steps can be changed later during update or end calls if the workflow changes.
71
+ * Starts a Live Activity on devices matched by API key scope and optional target channels. Supports segmented_progress, progress, and metrics activity types. For segmented_progress activities, number_of_steps can be changed later during update or end calls if the workflow changes.
72
72
  * Start a Live Activity
73
73
  */
74
74
  startLiveActivity(requestParameters: StartLiveActivityRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<LiveActivityStartResponse>;
75
75
  /**
76
- * Updates an existing Live Activity. If the per-activity token is not registered yet, the update is queued. Supports segmented_progress, progress, metrics, and the legacy counter/timer/countdown step-based activity types. For segmented_progress activities, you can increase or decrease number_of_steps here as the workflow changes.
76
+ * Updates an existing Live Activity. If the per-activity token is not registered yet, the update is queued. Supports segmented_progress, progress, and metrics activity types. For segmented_progress activities, you can increase or decrease number_of_steps here as the workflow changes.
77
77
  * Update a Live Activity
78
78
  */
79
79
  updateLiveActivityRaw(requestParameters: UpdateLiveActivityRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<LiveActivityUpdateResponse>>;
80
80
  /**
81
- * Updates an existing Live Activity. If the per-activity token is not registered yet, the update is queued. Supports segmented_progress, progress, metrics, and the legacy counter/timer/countdown step-based activity types. For segmented_progress activities, you can increase or decrease number_of_steps here as the workflow changes.
81
+ * Updates an existing Live Activity. If the per-activity token is not registered yet, the update is queued. Supports segmented_progress, progress, and metrics activity types. For segmented_progress activities, you can increase or decrease number_of_steps here as the workflow changes.
82
82
  * Update a Live Activity
83
83
  */
84
84
  updateLiveActivity(requestParameters: UpdateLiveActivityRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<LiveActivityUpdateResponse>;
@@ -20,7 +20,7 @@ const runtime = require("../runtime");
20
20
  */
21
21
  class LiveActivitiesApi extends runtime.BaseAPI {
22
22
  /**
23
- * Ends a Live Activity and archives its lifecycle. Supports segmented_progress, progress, metrics, and the legacy counter/timer/countdown step-based activity types. For segmented_progress activities, you can send the latest number_of_steps here if the workflow changed after start.
23
+ * Ends a Live Activity and archives its lifecycle. Supports segmented_progress, progress, and metrics activity types. For segmented_progress activities, you can send the latest number_of_steps here if the workflow changed after start.
24
24
  * End a Live Activity
25
25
  */
26
26
  async endLiveActivityRaw(requestParameters, initOverrides) {
@@ -47,7 +47,7 @@ class LiveActivitiesApi extends runtime.BaseAPI {
47
47
  return new runtime.JSONApiResponse(response);
48
48
  }
49
49
  /**
50
- * Ends a Live Activity and archives its lifecycle. Supports segmented_progress, progress, metrics, and the legacy counter/timer/countdown step-based activity types. For segmented_progress activities, you can send the latest number_of_steps here if the workflow changed after start.
50
+ * Ends a Live Activity and archives its lifecycle. Supports segmented_progress, progress, and metrics activity types. For segmented_progress activities, you can send the latest number_of_steps here if the workflow changed after start.
51
51
  * End a Live Activity
52
52
  */
53
53
  async endLiveActivity(requestParameters, initOverrides) {
@@ -128,7 +128,7 @@ class LiveActivitiesApi extends runtime.BaseAPI {
128
128
  return await response.value();
129
129
  }
130
130
  /**
131
- * Starts a Live Activity on devices matched by API key scope and optional target channels. Supports segmented_progress, progress, metrics, and the legacy counter/timer/countdown step-based activity types. For segmented_progress activities, number_of_steps can be changed later during update or end calls if the workflow changes.
131
+ * Starts a Live Activity on devices matched by API key scope and optional target channels. Supports segmented_progress, progress, and metrics activity types. For segmented_progress activities, number_of_steps can be changed later during update or end calls if the workflow changes.
132
132
  * Start a Live Activity
133
133
  */
134
134
  async startLiveActivityRaw(requestParameters, initOverrides) {
@@ -155,7 +155,7 @@ class LiveActivitiesApi extends runtime.BaseAPI {
155
155
  return new runtime.JSONApiResponse(response);
156
156
  }
157
157
  /**
158
- * Starts a Live Activity on devices matched by API key scope and optional target channels. Supports segmented_progress, progress, metrics, and the legacy counter/timer/countdown step-based activity types. For segmented_progress activities, number_of_steps can be changed later during update or end calls if the workflow changes.
158
+ * Starts a Live Activity on devices matched by API key scope and optional target channels. Supports segmented_progress, progress, and metrics activity types. For segmented_progress activities, number_of_steps can be changed later during update or end calls if the workflow changes.
159
159
  * Start a Live Activity
160
160
  */
161
161
  async startLiveActivity(requestParameters, initOverrides) {
@@ -163,7 +163,7 @@ class LiveActivitiesApi extends runtime.BaseAPI {
163
163
  return await response.value();
164
164
  }
165
165
  /**
166
- * Updates an existing Live Activity. If the per-activity token is not registered yet, the update is queued. Supports segmented_progress, progress, metrics, and the legacy counter/timer/countdown step-based activity types. For segmented_progress activities, you can increase or decrease number_of_steps here as the workflow changes.
166
+ * Updates an existing Live Activity. If the per-activity token is not registered yet, the update is queued. Supports segmented_progress, progress, and metrics activity types. For segmented_progress activities, you can increase or decrease number_of_steps here as the workflow changes.
167
167
  * Update a Live Activity
168
168
  */
169
169
  async updateLiveActivityRaw(requestParameters, initOverrides) {
@@ -190,7 +190,7 @@ class LiveActivitiesApi extends runtime.BaseAPI {
190
190
  return new runtime.JSONApiResponse(response);
191
191
  }
192
192
  /**
193
- * Updates an existing Live Activity. If the per-activity token is not registered yet, the update is queued. Supports segmented_progress, progress, metrics, and the legacy counter/timer/countdown step-based activity types. For segmented_progress activities, you can increase or decrease number_of_steps here as the workflow changes.
193
+ * Updates an existing Live Activity. If the per-activity token is not registered yet, the update is queued. Supports segmented_progress, progress, and metrics activity types. For segmented_progress activities, you can increase or decrease number_of_steps here as the workflow changes.
194
194
  * Update a Live Activity
195
195
  */
196
196
  async updateLiveActivity(requestParameters, initOverrides) {
@@ -0,0 +1,32 @@
1
+ /**
2
+ * ActivitySmith API
3
+ * Send push notifications and Live Activities to your own devices via a single API key.
4
+ *
5
+ * The version of the OpenAPI document: 1.0.0
6
+ *
7
+ *
8
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
9
+ * https://openapi-generator.tech
10
+ * Do not edit the class manually.
11
+ */
12
+ import * as runtime from '../runtime';
13
+ import type { MetricValueUpdateRequest, MetricValueUpdateResponse } from '../models/index';
14
+ export interface UpdateMetricValueRequest {
15
+ key: string;
16
+ metricValueUpdateRequest: MetricValueUpdateRequest;
17
+ }
18
+ /**
19
+ *
20
+ */
21
+ export declare class MetricsApi extends runtime.BaseAPI {
22
+ /**
23
+ * Updates the latest value for a metric displayed in ActivitySmith widgets. Create the metric in the web app first, then update its value using the key.
24
+ * Update a widget metric value
25
+ */
26
+ updateMetricValueRaw(requestParameters: UpdateMetricValueRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<MetricValueUpdateResponse>>;
27
+ /**
28
+ * Updates the latest value for a metric displayed in ActivitySmith widgets. Create the metric in the web app first, then update its value using the key.
29
+ * Update a widget metric value
30
+ */
31
+ updateMetricValue(requestParameters: UpdateMetricValueRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<MetricValueUpdateResponse>;
32
+ }
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ /* tslint:disable */
3
+ /* eslint-disable */
4
+ /**
5
+ * ActivitySmith API
6
+ * Send push notifications and Live Activities to your own devices via a single API key.
7
+ *
8
+ * The version of the OpenAPI document: 1.0.0
9
+ *
10
+ *
11
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
12
+ * https://openapi-generator.tech
13
+ * Do not edit the class manually.
14
+ */
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.MetricsApi = void 0;
17
+ const runtime = require("../runtime");
18
+ /**
19
+ *
20
+ */
21
+ class MetricsApi extends runtime.BaseAPI {
22
+ /**
23
+ * Updates the latest value for a metric displayed in ActivitySmith widgets. Create the metric in the web app first, then update its value using the key.
24
+ * Update a widget metric value
25
+ */
26
+ async updateMetricValueRaw(requestParameters, initOverrides) {
27
+ if (requestParameters['key'] == null) {
28
+ throw new runtime.RequiredError('key', 'Required parameter "key" was null or undefined when calling updateMetricValue().');
29
+ }
30
+ if (requestParameters['metricValueUpdateRequest'] == null) {
31
+ throw new runtime.RequiredError('metricValueUpdateRequest', 'Required parameter "metricValueUpdateRequest" was null or undefined when calling updateMetricValue().');
32
+ }
33
+ const queryParameters = {};
34
+ const headerParameters = {};
35
+ headerParameters['Content-Type'] = 'application/json';
36
+ if (this.configuration && this.configuration.accessToken) {
37
+ const token = this.configuration.accessToken;
38
+ const tokenString = await token("apiKeyAuth", []);
39
+ if (tokenString) {
40
+ headerParameters["Authorization"] = `Bearer ${tokenString}`;
41
+ }
42
+ }
43
+ const response = await this.request({
44
+ path: `/metrics/{key}/value`.replace(`{${"key"}}`, encodeURIComponent(String(requestParameters['key']))),
45
+ method: 'POST',
46
+ headers: headerParameters,
47
+ query: queryParameters,
48
+ body: requestParameters['metricValueUpdateRequest'],
49
+ }, initOverrides);
50
+ return new runtime.JSONApiResponse(response);
51
+ }
52
+ /**
53
+ * Updates the latest value for a metric displayed in ActivitySmith widgets. Create the metric in the web app first, then update its value using the key.
54
+ * Update a widget metric value
55
+ */
56
+ async updateMetricValue(requestParameters, initOverrides) {
57
+ const response = await this.updateMetricValueRaw(requestParameters, initOverrides);
58
+ return await response.value();
59
+ }
60
+ }
61
+ exports.MetricsApi = MetricsApi;
@@ -1,2 +1,3 @@
1
1
  export * from './LiveActivitiesApi';
2
+ export * from './MetricsApi';
2
3
  export * from './PushNotificationsApi';
@@ -17,4 +17,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  /* tslint:disable */
18
18
  /* eslint-disable */
19
19
  __exportStar(require("./LiveActivitiesApi"), exports);
20
+ __exportStar(require("./MetricsApi"), exports);
20
21
  __exportStar(require("./PushNotificationsApi"), exports);
@@ -79,7 +79,7 @@ export interface ChannelTarget {
79
79
  channels: Array<string>;
80
80
  }
81
81
  /**
82
- * End payload requires title. For segmented_progress include current_step and optionally number_of_steps. For progress include percentage or value with upper_limit. For metrics include a non-empty metrics array. Legacy counter/timer/countdown types also use current_step and number_of_steps. Type is optional when ending an existing activity. You can send an updated number_of_steps here if the workflow changed after start.
82
+ * End payload requires title. For segmented_progress include current_step and optionally number_of_steps. For progress include percentage or value with upper_limit. For metrics include a non-empty metrics array. Type is optional when ending an existing activity. You can send an updated number_of_steps here if the workflow changed after start.
83
83
  * @export
84
84
  * @interface ContentStateEnd
85
85
  */
@@ -171,9 +171,6 @@ export declare const ContentStateEndTypeEnum: {
171
171
  readonly SegmentedProgress: "segmented_progress";
172
172
  readonly Progress: "progress";
173
173
  readonly Metrics: "metrics";
174
- readonly Counter: "counter";
175
- readonly Timer: "timer";
176
- readonly Countdown: "countdown";
177
174
  };
178
175
  export type ContentStateEndTypeEnum = typeof ContentStateEndTypeEnum[keyof typeof ContentStateEndTypeEnum];
179
176
  /**
@@ -222,7 +219,7 @@ export declare const ContentStateEndStepColorsEnum: {
222
219
  };
223
220
  export type ContentStateEndStepColorsEnum = typeof ContentStateEndStepColorsEnum[keyof typeof ContentStateEndStepColorsEnum];
224
221
  /**
225
- * Start payload requires title and type. For segmented_progress include number_of_steps and current_step. For progress include percentage or value with upper_limit. For metrics include a non-empty metrics array. Legacy counter/timer/countdown types also use current_step and number_of_steps. For segmented_progress, number_of_steps is not locked and can be changed in later update or end calls.
222
+ * Start payload requires title and type. For segmented_progress include number_of_steps and current_step. For progress include percentage or value with upper_limit. For metrics include a non-empty metrics array. For segmented_progress, number_of_steps is not locked and can be changed in later update or end calls.
226
223
  * @export
227
224
  * @interface ContentStateStart
228
225
  */
@@ -308,9 +305,6 @@ export declare const ContentStateStartTypeEnum: {
308
305
  readonly SegmentedProgress: "segmented_progress";
309
306
  readonly Progress: "progress";
310
307
  readonly Metrics: "metrics";
311
- readonly Counter: "counter";
312
- readonly Timer: "timer";
313
- readonly Countdown: "countdown";
314
308
  };
315
309
  export type ContentStateStartTypeEnum = typeof ContentStateStartTypeEnum[keyof typeof ContentStateStartTypeEnum];
316
310
  /**
@@ -359,7 +353,7 @@ export declare const ContentStateStartStepColorsEnum: {
359
353
  };
360
354
  export type ContentStateStartStepColorsEnum = typeof ContentStateStartStepColorsEnum[keyof typeof ContentStateStartStepColorsEnum];
361
355
  /**
362
- * Update payload requires title. For segmented_progress include current_step and optionally number_of_steps. For progress include percentage or value with upper_limit. For metrics include a non-empty metrics array. Legacy counter/timer/countdown types also use current_step and number_of_steps. Type is optional when updating an existing activity. You can increase or decrease number_of_steps during updates.
356
+ * Update payload requires title. For segmented_progress include current_step and optionally number_of_steps. For progress include percentage or value with upper_limit. For metrics include a non-empty metrics array. Type is optional when updating an existing activity. You can increase or decrease number_of_steps during updates.
363
357
  * @export
364
358
  * @interface ContentStateUpdate
365
359
  */
@@ -445,9 +439,6 @@ export declare const ContentStateUpdateTypeEnum: {
445
439
  readonly SegmentedProgress: "segmented_progress";
446
440
  readonly Progress: "progress";
447
441
  readonly Metrics: "metrics";
448
- readonly Counter: "counter";
449
- readonly Timer: "timer";
450
- readonly Countdown: "countdown";
451
442
  };
452
443
  export type ContentStateUpdateTypeEnum = typeof ContentStateUpdateTypeEnum[keyof typeof ContentStateUpdateTypeEnum];
453
444
  /**
@@ -1009,6 +1000,66 @@ export declare const LiveActivityWebhookMethod: {
1009
1000
  readonly Post: "POST";
1010
1001
  };
1011
1002
  export type LiveActivityWebhookMethod = typeof LiveActivityWebhookMethod[keyof typeof LiveActivityWebhookMethod];
1003
+ /**
1004
+ *
1005
+ * @export
1006
+ * @interface MetricError
1007
+ */
1008
+ export interface MetricError {
1009
+ [key: string]: any | any;
1010
+ /**
1011
+ *
1012
+ * @type {string}
1013
+ * @memberof MetricError
1014
+ */
1015
+ error: string;
1016
+ /**
1017
+ *
1018
+ * @type {string}
1019
+ * @memberof MetricError
1020
+ */
1021
+ message?: string;
1022
+ }
1023
+ /**
1024
+ * Latest metric value to display in widgets.
1025
+ * @export
1026
+ * @interface MetricValueUpdateRequest
1027
+ */
1028
+ export interface MetricValueUpdateRequest {
1029
+ [key: string]: any | any;
1030
+ /**
1031
+ *
1032
+ * @type {MetricValueUpdateRequestValue}
1033
+ * @memberof MetricValueUpdateRequest
1034
+ */
1035
+ value: MetricValueUpdateRequestValue;
1036
+ /**
1037
+ * Optional ISO timestamp for when the metric value was measured. Defaults to the server receive time.
1038
+ * @type {string}
1039
+ * @memberof MetricValueUpdateRequest
1040
+ */
1041
+ timestamp?: string;
1042
+ }
1043
+ /**
1044
+ * @type MetricValueUpdateRequestValue
1045
+ *
1046
+ * @export
1047
+ */
1048
+ export type MetricValueUpdateRequestValue = number | string;
1049
+ /**
1050
+ *
1051
+ * @export
1052
+ * @interface MetricValueUpdateResponse
1053
+ */
1054
+ export interface MetricValueUpdateResponse {
1055
+ [key: string]: any | any;
1056
+ /**
1057
+ *
1058
+ * @type {boolean}
1059
+ * @memberof MetricValueUpdateResponse
1060
+ */
1061
+ success: boolean;
1062
+ }
1012
1063
  /**
1013
1064
  *
1014
1065
  * @export
@@ -1248,7 +1299,7 @@ export interface RateLimitError {
1248
1299
  */
1249
1300
  export type SendPushNotification429Response = LiveActivityLimitError | RateLimitError;
1250
1301
  /**
1251
- * Current state for a managed Live Activity stream. Include type on the first PUT, and whenever the stream may need to start a fresh activity. Supports segmented_progress, progress, metrics, and the legacy counter/timer/countdown step-based types.
1302
+ * Current state for a managed Live Activity stream. Include type on the first PUT, and whenever the stream may need to start a fresh activity. Supports segmented_progress, progress, and metrics types.
1252
1303
  * @export
1253
1304
  * @interface StreamContentState
1254
1305
  */
@@ -1267,13 +1318,13 @@ export interface StreamContentState {
1267
1318
  */
1268
1319
  subtitle?: string;
1269
1320
  /**
1270
- * Use for segmented_progress, counter, timer, and countdown.
1321
+ * Use for segmented_progress.
1271
1322
  * @type {number}
1272
1323
  * @memberof StreamContentState
1273
1324
  */
1274
1325
  number_of_steps?: number;
1275
1326
  /**
1276
- * Use for segmented_progress, counter, timer, and countdown.
1327
+ * Use for segmented_progress.
1277
1328
  * @type {number}
1278
1329
  * @memberof StreamContentState
1279
1330
  */
@@ -1346,9 +1397,6 @@ export declare const StreamContentStateTypeEnum: {
1346
1397
  readonly SegmentedProgress: "segmented_progress";
1347
1398
  readonly Progress: "progress";
1348
1399
  readonly Metrics: "metrics";
1349
- readonly Counter: "counter";
1350
- readonly Timer: "timer";
1351
- readonly Countdown: "countdown";
1352
1400
  };
1353
1401
  export type StreamContentStateTypeEnum = typeof StreamContentStateTypeEnum[keyof typeof StreamContentStateTypeEnum];
1354
1402
  /**
@@ -7,10 +7,7 @@ exports.StreamContentStateStepColorsEnum = exports.StreamContentStateStepColorEn
7
7
  exports.ContentStateEndTypeEnum = {
8
8
  SegmentedProgress: 'segmented_progress',
9
9
  Progress: 'progress',
10
- Metrics: 'metrics',
11
- Counter: 'counter',
12
- Timer: 'timer',
13
- Countdown: 'countdown'
10
+ Metrics: 'metrics'
14
11
  };
15
12
  /**
16
13
  * @export
@@ -60,10 +57,7 @@ exports.ContentStateEndStepColorsEnum = {
60
57
  exports.ContentStateStartTypeEnum = {
61
58
  SegmentedProgress: 'segmented_progress',
62
59
  Progress: 'progress',
63
- Metrics: 'metrics',
64
- Counter: 'counter',
65
- Timer: 'timer',
66
- Countdown: 'countdown'
60
+ Metrics: 'metrics'
67
61
  };
68
62
  /**
69
63
  * @export
@@ -113,10 +107,7 @@ exports.ContentStateStartStepColorsEnum = {
113
107
  exports.ContentStateUpdateTypeEnum = {
114
108
  SegmentedProgress: 'segmented_progress',
115
109
  Progress: 'progress',
116
- Metrics: 'metrics',
117
- Counter: 'counter',
118
- Timer: 'timer',
119
- Countdown: 'countdown'
110
+ Metrics: 'metrics'
120
111
  };
121
112
  /**
122
113
  * @export
@@ -214,10 +205,7 @@ exports.PushNotificationWebhookMethod = {
214
205
  exports.StreamContentStateTypeEnum = {
215
206
  SegmentedProgress: 'segmented_progress',
216
207
  Progress: 'progress',
217
- Metrics: 'metrics',
218
- Counter: 'counter',
219
- Timer: 'timer',
220
- Countdown: 'countdown'
208
+ Metrics: 'metrics'
221
209
  };
222
210
  /**
223
211
  * @export
@@ -1,4 +1,4 @@
1
- import { PushNotificationsApi, LiveActivitiesApi } from "../generated/index";
1
+ import { PushNotificationsApi, LiveActivitiesApi, MetricsApi } from "../generated/index";
2
2
  export interface ActivitySmithOptions {
3
3
  apiKey: string;
4
4
  }
@@ -12,6 +12,12 @@ type EndRequestBody = Parameters<LiveActivitiesApi["endLiveActivity"]>[0]["liveA
12
12
  type StreamRequestBody = Parameters<LiveActivitiesApi["reconcileLiveActivityStream"]>[0]["liveActivityStreamRequest"];
13
13
  type StreamDeleteRequestBody = Parameters<LiveActivitiesApi["endLiveActivityStream"]>[0]["liveActivityStreamDeleteRequest"];
14
14
  type LiveInitOverrides = Parameters<LiveActivitiesApi["startLiveActivity"]>[1];
15
+ type MetricUpdateParameters = Parameters<MetricsApi["updateMetricValue"]>[0];
16
+ type MetricRawParameters = Parameters<MetricsApi["updateMetricValueRaw"]>[0];
17
+ type MetricUpdateRequestBody = MetricUpdateParameters["metricValueUpdateRequest"];
18
+ type MetricValue = MetricUpdateRequestBody["value"];
19
+ type MetricUpdateOptions = Omit<MetricUpdateRequestBody, "value">;
20
+ type MetricInitOverrides = Parameters<MetricsApi["updateMetricValue"]>[1];
15
21
  type PushSendRequest = PushRequestBody & {
16
22
  channels?: string[];
17
23
  };
@@ -47,9 +53,17 @@ export declare class LiveActivitiesResource {
47
53
  reconcileLiveActivityStreamRaw(...args: Parameters<LiveActivitiesApi["reconcileLiveActivityStreamRaw"]>): Promise<import("../generated/runtime").ApiResponse<import("../generated/models").LiveActivityStreamPutResponse>>;
48
54
  endLiveActivityStreamRaw(...args: Parameters<LiveActivitiesApi["endLiveActivityStreamRaw"]>): Promise<import("../generated/runtime").ApiResponse<import("../generated/models").LiveActivityStreamDeleteResponse>>;
49
55
  }
56
+ export declare class MetricsResource {
57
+ private readonly api;
58
+ constructor(api: MetricsApi);
59
+ update(key: string, valueOrRequest: MetricValue | MetricUpdateRequestBody, options?: MetricUpdateOptions, initOverrides?: MetricInitOverrides): Promise<import("../generated/models").MetricValueUpdateResponse>;
60
+ updateMetricValue(requestParameters: MetricUpdateParameters, initOverrides?: MetricInitOverrides): Promise<import("../generated/models").MetricValueUpdateResponse>;
61
+ updateMetricValueRaw(requestParameters: MetricRawParameters, initOverrides?: MetricInitOverrides): Promise<import("../generated/runtime").ApiResponse<import("../generated/models").MetricValueUpdateResponse>>;
62
+ }
50
63
  export declare class ActivitySmith {
51
64
  readonly notifications: NotificationsResource;
52
65
  readonly liveActivities: LiveActivitiesResource;
66
+ readonly metrics: MetricsResource;
53
67
  constructor(opts: ActivitySmithOptions);
54
68
  }
55
69
  export {};
@@ -1,7 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ActivitySmith = exports.LiveActivitiesResource = exports.NotificationsResource = void 0;
3
+ exports.ActivitySmith = exports.MetricsResource = exports.LiveActivitiesResource = exports.NotificationsResource = void 0;
4
4
  const index_1 = require("../generated/index");
5
+ const SDK_VERSION = "1.1.0";
6
+ const SDK_HEADER_NAME = "X-ActivitySmith-SDK";
7
+ const SDK_HEADER_VALUE = `node-v${SDK_VERSION}`;
5
8
  function withTargetChannels(request) {
6
9
  const channels = request.channels;
7
10
  if (!channels || channels.length === 0 || request.target) {
@@ -31,6 +34,20 @@ function assertValidPushRequest(request) {
31
34
  throw new Error("ActivitySmith: media cannot be combined with actions");
32
35
  }
33
36
  }
37
+ function toMetricUpdateRequest(valueOrRequest, options) {
38
+ if (typeof valueOrRequest === "object" &&
39
+ valueOrRequest !== null &&
40
+ "value" in valueOrRequest) {
41
+ return {
42
+ ...valueOrRequest,
43
+ ...options,
44
+ };
45
+ }
46
+ return {
47
+ value: valueOrRequest,
48
+ ...options,
49
+ };
50
+ }
34
51
  class NotificationsResource {
35
52
  constructor(api) {
36
53
  this.api = api;
@@ -109,6 +126,25 @@ class LiveActivitiesResource {
109
126
  }
110
127
  }
111
128
  exports.LiveActivitiesResource = LiveActivitiesResource;
129
+ class MetricsResource {
130
+ constructor(api) {
131
+ this.api = api;
132
+ }
133
+ update(key, valueOrRequest, options, initOverrides) {
134
+ return this.api.updateMetricValue({
135
+ key,
136
+ metricValueUpdateRequest: toMetricUpdateRequest(valueOrRequest, options),
137
+ }, initOverrides);
138
+ }
139
+ // Backward-compatible generated-style aliases.
140
+ updateMetricValue(requestParameters, initOverrides) {
141
+ return this.api.updateMetricValue(requestParameters, initOverrides);
142
+ }
143
+ updateMetricValueRaw(requestParameters, initOverrides) {
144
+ return this.api.updateMetricValueRaw(requestParameters, initOverrides);
145
+ }
146
+ }
147
+ exports.MetricsResource = MetricsResource;
112
148
  class ActivitySmith {
113
149
  constructor(opts) {
114
150
  if (!opts?.apiKey) {
@@ -117,9 +153,13 @@ class ActivitySmith {
117
153
  // basePath omitted on purpose — it will use the default from the generated runtime
118
154
  const config = new index_1.Configuration({
119
155
  accessToken: opts.apiKey,
156
+ headers: {
157
+ [SDK_HEADER_NAME]: SDK_HEADER_VALUE,
158
+ },
120
159
  });
121
160
  this.notifications = new NotificationsResource(new index_1.PushNotificationsApi(config));
122
161
  this.liveActivities = new LiveActivitiesResource(new index_1.LiveActivitiesApi(config));
162
+ this.metrics = new MetricsResource(new index_1.MetricsApi(config));
123
163
  }
124
164
  }
125
165
  exports.ActivitySmith = ActivitySmith;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "activitysmith",
3
- "version": "1.1.0",
3
+ "version": "1.2.1",
4
4
  "description": "Official ActivitySmith Node.js SDK",
5
5
  "keywords": [
6
6
  "activitysmith",