Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions generated/apis/AppIconBadgesApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ export interface UpdateAppIconBadgeCountRequest {
export class AppIconBadgesApi extends runtime.BaseAPI {

/**
* Shows a number on the ActivitySmith app icon.
* Set App Icon Badge Count
* Shows a number on the ActivitySmith app icon. Requires Push Notifications enabled for ActivitySmith on the device.
* Set App Icon Badge
*/
async updateAppIconBadgeCountRaw(requestParameters: UpdateAppIconBadgeCountRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<AppIconBadgeCountUpdateResponse>> {
if (requestParameters['appIconBadgeCountUpdateRequest'] == null) {
Expand Down Expand Up @@ -72,8 +72,8 @@ export class AppIconBadgesApi extends runtime.BaseAPI {
}

/**
* Shows a number on the ActivitySmith app icon.
* Set App Icon Badge Count
* Shows a number on the ActivitySmith app icon. Requires Push Notifications enabled for ActivitySmith on the device.
* Set App Icon Badge
*/
async updateAppIconBadgeCount(requestParameters: UpdateAppIconBadgeCountRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<AppIconBadgeCountUpdateResponse> {
const response = await this.updateAppIconBadgeCountRaw(requestParameters, initOverrides);
Expand Down
57 changes: 55 additions & 2 deletions generated/apis/MetricsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import * as runtime from '../runtime';
import type {
MetricError,
MetricResponse,
MetricUpsertRequest,
MetricValueUpdateRequest,
MetricValueUpdateResponse,
RateLimitError,
Expand All @@ -26,13 +28,18 @@ export interface UpdateMetricValueRequest {
metricValueUpdateRequest: MetricValueUpdateRequest;
}

export interface UpsertMetricRequest {
key: string;
metricUpsertRequest?: MetricUpsertRequest;
}

/**
*
*/
export class MetricsApi extends runtime.BaseAPI {

/**
* 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. Metric updates have an independent 300-requests-per-minute account allowance. They do not consume the Push Notification, badge, or Live Activity allowances.
* Updates the latest value for a metric displayed in ActivitySmith widgets. If no metric uses the key yet, the first value creates one: the label comes from the key, numeric values get the number format, and text values get the string format. To choose a currency, percent, or unit format, create the metric first with PUT /metrics/{key} or in the web app. A deleted metric is not recreated by new values; the request returns 404 with code metric_deleted. Each account can have up to 100 metrics created through the API. Metric updates have an independent 300-requests-per-minute account allowance. They do not consume the Push Notification, badge, or Live Activity allowances.
* Update a widget metric value
*/
async updateMetricValueRaw(requestParameters: UpdateMetricValueRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<MetricValueUpdateResponse>> {
Expand Down Expand Up @@ -76,12 +83,58 @@ export class MetricsApi extends runtime.BaseAPI {
}

/**
* 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. Metric updates have an independent 300-requests-per-minute account allowance. They do not consume the Push Notification, badge, or Live Activity allowances.
* Updates the latest value for a metric displayed in ActivitySmith widgets. If no metric uses the key yet, the first value creates one: the label comes from the key, numeric values get the number format, and text values get the string format. To choose a currency, percent, or unit format, create the metric first with PUT /metrics/{key} or in the web app. A deleted metric is not recreated by new values; the request returns 404 with code metric_deleted. Each account can have up to 100 metrics created through the API. Metric updates have an independent 300-requests-per-minute account allowance. They do not consume the Push Notification, badge, or Live Activity allowances.
* Update a widget metric value
*/
async updateMetricValue(requestParameters: UpdateMetricValueRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<MetricValueUpdateResponse> {
const response = await this.updateMetricValueRaw(requestParameters, initOverrides);
return await response.value();
}

/**
* Creates a metric for widgets, or updates the fields sent for an existing metric. Omitted fields keep their current values, so repeating the same request does not change the metric. Changing between the string format and a numeric format clears the latest value. Shares the metric account allowance of 300 requests per minute and is not a billable metric update.
* Create or update a widget metric
*/
async upsertMetricRaw(requestParameters: UpsertMetricRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<MetricResponse>> {
if (requestParameters['key'] == null) {
throw new runtime.RequiredError(
'key',
'Required parameter "key" was null or undefined when calling upsertMetric().'
);
}

const queryParameters: any = {};

const headerParameters: runtime.HTTPHeaders = {};

headerParameters['Content-Type'] = 'application/json';

if (this.configuration && this.configuration.accessToken) {
const token = this.configuration.accessToken;
const tokenString = await token("apiKeyAuth", []);

if (tokenString) {
headerParameters["Authorization"] = `Bearer ${tokenString}`;
}
}
const response = await this.request({
path: `/metrics/{key}`.replace(`{${"key"}}`, encodeURIComponent(String(requestParameters['key']))),
method: 'PUT',
headers: headerParameters,
query: queryParameters,
body: requestParameters['metricUpsertRequest'],
}, initOverrides);

return new runtime.JSONApiResponse(response);
}

/**
* Creates a metric for widgets, or updates the fields sent for an existing metric. Omitted fields keep their current values, so repeating the same request does not change the metric. Changing between the string format and a numeric format clears the latest value. Shares the metric account allowance of 300 requests per minute and is not a billable metric update.
* Create or update a widget metric
*/
async upsertMetric(requestParameters: UpsertMetricRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<MetricResponse> {
const response = await this.upsertMetricRaw(requestParameters, initOverrides);
return await response.value();
}

}
177 changes: 176 additions & 1 deletion generated/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export interface AppIconBadgeCountUpdateResponse {
*/
badge: number;
/**
* Number of devices whose App Icon Badge Count was updated.
* Number of devices whose App Icon Badge was updated.
* @type {number}
* @memberof AppIconBadgeCountUpdateResponse
*/
Expand Down Expand Up @@ -1743,6 +1743,102 @@ export type LiveActivityWebhookMethod = typeof LiveActivityWebhookMethod[keyof t
* @export
*/
export type MetadataValue = boolean | number | string;
/**
*
* @export
* @interface Metric
*/
export interface Metric {
/**
*
* @type {string}
* @memberof Metric
*/
public_id: string;
/**
*
* @type {string}
* @memberof Metric
*/
key: string;
/**
*
* @type {string}
* @memberof Metric
*/
label: string;
/**
*
* @type {string}
* @memberof Metric
*/
format: MetricFormatEnum;
/**
*
* @type {string}
* @memberof Metric
*/
currency_code: string | null;
/**
*
* @type {string}
* @memberof Metric
*/
unit: string | null;
/**
*
* @type {string}
* @memberof Metric
*/
unit_spacing: MetricUnitSpacingEnum;
/**
*
* @type {any}
* @memberof Metric
*/
latest_value: any | null;
/**
*
* @type {string}
* @memberof Metric
*/
latest_value_at: string | null;
/**
*
* @type {string}
* @memberof Metric
*/
created_at: string;
/**
*
* @type {string}
* @memberof Metric
*/
updated_at: string;
}


/**
* @export
*/
export const MetricFormatEnum = {
Number: 'number',
Currency: 'currency',
Percent: 'percent',
Unit: 'unit',
String: 'string'
} as const;
export type MetricFormatEnum = typeof MetricFormatEnum[keyof typeof MetricFormatEnum];

/**
* @export
*/
export const MetricUnitSpacingEnum = {
None: 'none',
Space: 'space'
} as const;
export type MetricUnitSpacingEnum = typeof MetricUnitSpacingEnum[keyof typeof MetricUnitSpacingEnum];

/**
*
* @export
Expand All @@ -1762,6 +1858,79 @@ export interface MetricError {
*/
message?: string;
}
/**
*
* @export
* @interface MetricResponse
*/
export interface MetricResponse {
/**
*
* @type {Metric}
* @memberof MetricResponse
*/
metric: Metric;
}
/**
* Metric definition. Omitted fields keep their current values, or use defaults for a new metric: a label made from the key and the number format.
* @export
* @interface MetricUpsertRequest
*/
export interface MetricUpsertRequest {
/**
* Name shown on the widget.
* @type {string}
* @memberof MetricUpsertRequest
*/
label?: string;
/**
* How widgets display the value: number (1,234), currency (requires currency_code), percent (send 99.9 to show 99.9%), unit (a number with a unit suffix, such as 120 ms), or string (text up to 64 characters). Defaults to number for a new metric.
* @type {string}
* @memberof MetricUpsertRequest
*/
format?: MetricUpsertRequestFormatEnum;
/**
* 3-letter ISO 4217 currency code, such as USD. Required for the currency format.
* @type {string}
* @memberof MetricUpsertRequest
*/
currency_code?: string;
/**
* Unit suffix for the unit format, such as ms or GB.
* @type {string}
* @memberof MetricUpsertRequest
*/
unit?: string;
/**
* For the unit format: none shows 120ms, space shows 120 ms.
* @type {string}
* @memberof MetricUpsertRequest
*/
unit_spacing?: MetricUpsertRequestUnitSpacingEnum;
}


/**
* @export
*/
export const MetricUpsertRequestFormatEnum = {
Number: 'number',
Currency: 'currency',
Percent: 'percent',
Unit: 'unit',
String: 'string'
} as const;
export type MetricUpsertRequestFormatEnum = typeof MetricUpsertRequestFormatEnum[keyof typeof MetricUpsertRequestFormatEnum];

/**
* @export
*/
export const MetricUpsertRequestUnitSpacingEnum = {
None: 'none',
Space: 'space'
} as const;
export type MetricUpsertRequestUnitSpacingEnum = typeof MetricUpsertRequestUnitSpacingEnum[keyof typeof MetricUpsertRequestUnitSpacingEnum];

/**
* Latest metric value to display in widgets.
* @export
Expand Down Expand Up @@ -1799,6 +1968,12 @@ export interface MetricValueUpdateResponse {
* @memberof MetricValueUpdateResponse
*/
success: boolean;
/**
* true when this request created the metric because no metric used the key yet.
* @type {boolean}
* @memberof MetricValueUpdateResponse
*/
created?: boolean;
}
/**
*
Expand Down
4 changes: 2 additions & 2 deletions generated/openapi-source.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"repository": "ActivitySmithHQ/activitysmith-backend",
"commit": "ab7064d65ad2097e3b57dc435c10b4f80a0ee27e",
"commit": "7bf9c3d88459fe3f122810979a45da0a1e6fd2d6",
"path": "openapi.json",
"sha256": "f0548e423e06f90169dae8d935b08f78291e9dbf95d4ae591e6d10d8eb269448"
"sha256": "6987f90b106e28a0ab8058f43309e7a9f045c7c54d27ce90bbdd5966c3f99f7a"
}
25 changes: 25 additions & 0 deletions src/ActivitySmith.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ type MetricUpdateRequestBody = MetricUpdateParameters["metricValueUpdateRequest"
type MetricValue = MetricUpdateRequestBody["value"];
type MetricUpdateOptions = Omit<MetricUpdateRequestBody, "value">;
type MetricInitOverrides = Parameters<MetricsApi["updateMetricValue"]>[1];
type MetricUpsertParameters = Parameters<MetricsApi["upsertMetric"]>[0];
type MetricUpsertRawParameters = Parameters<MetricsApi["upsertMetricRaw"]>[0];
type MetricDefinition = NonNullable<MetricUpsertParameters["metricUpsertRequest"]>;
type AppIconBadgeRequestBody =
Parameters<AppIconBadgesApi["updateAppIconBadgeCount"]>[0]["appIconBadgeCountUpdateRequest"];
type AppIconBadgeInitOverrides = Parameters<AppIconBadgesApi["updateAppIconBadgeCount"]>[1];
Expand Down Expand Up @@ -399,7 +402,29 @@ export class MetricsResource {
);
}

/**
* Creates the metric, or updates the fields sent for an existing one.
* Omitted fields keep their current values, so it is safe to call on every start.
*/
create(key: string, definition?: MetricDefinition, initOverrides?: MetricInitOverrides) {
return this.api.upsertMetric(
{
key,
...(definition ? { metricUpsertRequest: definition } : {}),
},
initOverrides,
);
}

// Backward-compatible generated-style aliases.
upsertMetric(requestParameters: MetricUpsertParameters, initOverrides?: MetricInitOverrides) {
return this.api.upsertMetric(requestParameters, initOverrides);
}

upsertMetricRaw(requestParameters: MetricUpsertRawParameters, initOverrides?: MetricInitOverrides) {
return this.api.upsertMetricRaw(requestParameters, initOverrides);
}

updateMetricValue(requestParameters: MetricUpdateParameters, initOverrides?: MetricInitOverrides) {
return this.api.updateMetricValue(requestParameters, initOverrides);
}
Expand Down
Loading
Loading