activitysmith-cli 1.17.0 → 1.18.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.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/src/cli.js +73 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "activitysmith-cli",
3
- "version": "1.17.0",
3
+ "version": "1.18.0",
4
4
  "description": "Command-line interface for ActivitySmith. Send Push Notifications, start, update, and end Live Activities, and set App Icon Badge Counts from your terminal.",
5
5
  "keywords": [
6
6
  "activitysmith",
@@ -42,7 +42,7 @@
42
42
  "test": "node --test"
43
43
  },
44
44
  "dependencies": {
45
- "activitysmith": "^1.14.0",
45
+ "activitysmith": "^1.15.0",
46
46
  "commander": "^12.1.0"
47
47
  }
48
48
  }
package/src/cli.js CHANGED
@@ -1282,10 +1282,11 @@ const outputResult = (payload, options, lines) => {
1282
1282
  lines.filter(Boolean).forEach((line) => console.log(line));
1283
1283
  };
1284
1284
 
1285
- program
1285
+ const pushCommand = program
1286
1286
  .command("push")
1287
- .description("Send a push notification, or replace one you already sent")
1288
- .requiredOption("--title <title>", "Push title")
1287
+ .description("Send a push notification, or replace or dismiss one you already sent")
1288
+ // Not requiredOption: commander would then demand --title for the dismiss subcommand too.
1289
+ .option("--title <title>", "Push title (required to send or replace)")
1289
1290
  .option(
1290
1291
  "--replace <notification-id>",
1291
1292
  "Silently replace a sent push notification, using the notification ID from its send output"
@@ -1322,6 +1323,10 @@ program
1322
1323
  .action(async (options) => {
1323
1324
  const globalOptions = program.opts();
1324
1325
 
1326
+ if (options.title === undefined) {
1327
+ pushCommand.error("error: required option '--title <title>' not specified");
1328
+ }
1329
+
1325
1330
  try {
1326
1331
  const apiKey = await requireApiKey(globalOptions);
1327
1332
  const client = createClient(apiKey);
@@ -1390,6 +1395,35 @@ program
1390
1395
  }
1391
1396
  });
1392
1397
 
1398
+ pushCommand
1399
+ .command("dismiss")
1400
+ .description(
1401
+ "Clear a sent push notification from the Lock Screen and Notification Center. History keeps it."
1402
+ )
1403
+ .argument("<notification-id>", "Notification ID from the push send output")
1404
+ .action(async (notificationId) => {
1405
+ const globalOptions = program.opts();
1406
+
1407
+ try {
1408
+ const id = String(notificationId).trim();
1409
+ if (!id) {
1410
+ throw new Error("Notification ID is required.");
1411
+ }
1412
+ const apiKey = await requireApiKey(globalOptions);
1413
+ const client = createClient(apiKey);
1414
+ const response = await client.notifications.dismiss(id);
1415
+ const dismissedAt = response?.dismissed_at ?? response?.dismissedAt;
1416
+
1417
+ outputResult(response, globalOptions, [
1418
+ "Push dismissed.",
1419
+ `Notification ID: ${response?.notification_id ?? response?.notificationId ?? id}`,
1420
+ dismissedAt ? `Dismissed at: ${dismissedAt}` : null,
1421
+ ]);
1422
+ } catch (error) {
1423
+ await handleError(error, globalOptions);
1424
+ }
1425
+ });
1426
+
1393
1427
  program
1394
1428
  .command("badge")
1395
1429
  .alias("badge-count")
@@ -1432,7 +1466,42 @@ program
1432
1466
  const metricsCommand = program
1433
1467
  .command("metrics")
1434
1468
  .alias("metric")
1435
- .description("Update widget metric values");
1469
+ .description("Create widget metrics and update their values");
1470
+
1471
+ metricsCommand
1472
+ .command("create")
1473
+ .description("Create a widget metric, or update the fields you pass for an existing one")
1474
+ .argument("<metric-key>", "Metric key")
1475
+ .option("--label <label>", "Name shown on the widget (defaults to a label made from the key)")
1476
+ .option("--format <format>", "number, currency, percent, unit, or string (defaults to number)")
1477
+ .option("--currency-code <code>", "3-letter ISO currency code, required for the currency format")
1478
+ .option("--unit <unit>", "Unit suffix for the unit format, such as ms or GB")
1479
+ .option("--unit-spacing <spacing>", "For the unit format: none (120ms) or space (120 ms)")
1480
+ .action(async (metricKey, options) => {
1481
+ const globalOptions = program.opts();
1482
+
1483
+ try {
1484
+ const apiKey = await requireApiKey(globalOptions);
1485
+ const client = createClient(apiKey);
1486
+ const definition = Object.fromEntries(
1487
+ Object.entries({
1488
+ label: options.label,
1489
+ format: options.format,
1490
+ currency_code: options.currencyCode,
1491
+ unit: options.unit,
1492
+ unit_spacing: options.unitSpacing,
1493
+ }).filter(([, value]) => value !== undefined)
1494
+ );
1495
+ const response = await client.metrics.create(
1496
+ metricKey,
1497
+ Object.keys(definition).length > 0 ? definition : undefined
1498
+ );
1499
+
1500
+ outputResult(response, globalOptions, ["Metric saved."]);
1501
+ } catch (error) {
1502
+ await handleError(error, globalOptions);
1503
+ }
1504
+ });
1436
1505
 
1437
1506
  metricsCommand
1438
1507
  .command("update")