@perspectask/sdk 1.1.0 → 1.2.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/dist/index.js CHANGED
@@ -846,6 +846,30 @@ var Tasks = class {
846
846
  }
847
847
  });
848
848
  }
849
+ /**
850
+ * List the history of all tasks
851
+ *
852
+ * Every change to your tasks, newest first: status, priority, deadline, parents, title and description edits. Recorded automatically on every change; nobody can edit it. Changes made through the API or a connected app carry an `actor`. Encrypted and deleted tasks are left out.
853
+ */
854
+ static listTasksHistory(options) {
855
+ return (options?.client ?? client).get({
856
+ security: [{ scheme: "bearer", type: "http" }],
857
+ url: "/tasks/history",
858
+ ...options
859
+ });
860
+ }
861
+ /**
862
+ * List the history of a task
863
+ *
864
+ * Every change to one task, newest first. Recorded automatically on every change; nobody can edit it. Changes made through the API or a connected app carry an `actor`.
865
+ */
866
+ static listTaskHistory(options) {
867
+ return (options.client ?? client).get({
868
+ security: [{ scheme: "bearer", type: "http" }],
869
+ url: "/tasks/{id}/history",
870
+ ...options
871
+ });
872
+ }
849
873
  };
850
874
  var PullRequests = class {
851
875
  /**
@@ -957,6 +981,72 @@ var Kpis = class {
957
981
  });
958
982
  }
959
983
  };
984
+ var Timers = class {
985
+ /**
986
+ * Get the running timer and time worked today
987
+ *
988
+ * The running timer, if any, and the seconds of finished timers today. Pass `day_start` with the user's local midnight so today follows their time zone.
989
+ */
990
+ static getTimerStatus(options) {
991
+ return (options?.client ?? client).get({
992
+ security: [{ scheme: "bearer", type: "http" }],
993
+ url: "/timers/status",
994
+ ...options
995
+ });
996
+ }
997
+ /**
998
+ * List timers
999
+ *
1000
+ * Your work sessions, newest first: which task, when it started and ended, and its duration in seconds. Filter by task with `task_id`. Timers of encrypted tasks are included (they hold no task content).
1001
+ */
1002
+ static listTimers(options) {
1003
+ return (options?.client ?? client).get({
1004
+ security: [{ scheme: "bearer", type: "http" }],
1005
+ url: "/timers",
1006
+ ...options
1007
+ });
1008
+ }
1009
+ /**
1010
+ * Start a timer on a task
1011
+ *
1012
+ * Start tracking time on a task. Only one timer runs at a time, so a timer running on another task is stopped first (returned as `stopped`). Starting the task that already runs changes nothing (200, `already_running`). Refused for a completed or cancelled task (400) and an encrypted one (403).
1013
+ */
1014
+ static startTaskTimer(options) {
1015
+ return (options.client ?? client).post({
1016
+ security: [{ scheme: "bearer", type: "http" }],
1017
+ url: "/tasks/{id}/timers",
1018
+ ...options
1019
+ });
1020
+ }
1021
+ /**
1022
+ * Stop the running timer
1023
+ *
1024
+ * Stop whatever timer is running. A timer stopped under 5 seconds is deleted instead of kept (`discarded: true`).
1025
+ */
1026
+ static stopTimer(options) {
1027
+ return (options?.client ?? client).post({
1028
+ security: [{ scheme: "bearer", type: "http" }],
1029
+ url: "/timers/stop",
1030
+ ...options
1031
+ });
1032
+ }
1033
+ /**
1034
+ * Update a timer
1035
+ *
1036
+ * Change when a finished timer started and/or ended, e.g. to fix a forgotten stop. Refused for a running timer, a date in the future, a start after the end, or an overlap with another timer (400). Deleting a timer is only possible in the web app.
1037
+ */
1038
+ static updateTimer(options) {
1039
+ return (options.client ?? client).patch({
1040
+ security: [{ scheme: "bearer", type: "http" }],
1041
+ url: "/timers/{timerId}",
1042
+ ...options,
1043
+ headers: {
1044
+ "Content-Type": "application/json",
1045
+ ...options.headers
1046
+ }
1047
+ });
1048
+ }
1049
+ };
960
1050
 
961
1051
  // src/generated/zod.gen.ts
962
1052
  import * as z from "zod/mini";
@@ -1066,6 +1156,74 @@ var zKpiEntry = z.object({
1066
1156
  description: "Only present when the value is end-to-end encrypted and so not readable over the API."
1067
1157
  }))
1068
1158
  });
1159
+ var zTimer = z.object({
1160
+ id: z.uuid().register(z.globalRegistry, {
1161
+ description: "Id of this timer. Pass it to update it."
1162
+ }),
1163
+ task_id: z.string().check(z.regex(/^[0-9a-fA-F]{3,32}$|^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/)).register(z.globalRegistry, {
1164
+ description: "The task (short id). Its title comes from `GET /tasks/{id}`."
1165
+ }),
1166
+ started_at: z.string().register(z.globalRegistry, {
1167
+ description: "ISO 8601 UTC instant."
1168
+ }),
1169
+ ended_at: z.optional(z.string().register(z.globalRegistry, {
1170
+ description: "ISO 8601 UTC instant. Omitted while it runs."
1171
+ })),
1172
+ duration: z.optional(z.int().register(z.globalRegistry, {
1173
+ description: "Seconds between start and end. Omitted while it runs."
1174
+ })),
1175
+ running: z.optional(z.literal(true).register(z.globalRegistry, {
1176
+ description: "Only present on the running timer."
1177
+ })),
1178
+ discarded: z.optional(z.literal(true).register(z.globalRegistry, {
1179
+ description: "Only on a stop: the timer ran under 5 seconds, so it was deleted instead of kept."
1180
+ }))
1181
+ });
1182
+ var zTimerStatus = z.object({
1183
+ worked_today: z.int().register(z.globalRegistry, {
1184
+ description: "Seconds of finished timers since the start of the day (`day_start`, default midnight UTC)."
1185
+ }),
1186
+ running: z.optional(z.intersection(zTimer, z.unknown().register(z.globalRegistry, {
1187
+ description: "The running timer. Omitted when none runs."
1188
+ })))
1189
+ });
1190
+ var zStartTimerResponse = z.object({
1191
+ timer: z.intersection(zTimer, z.unknown().register(z.globalRegistry, {
1192
+ description: "The running timer on this task."
1193
+ })),
1194
+ stopped: z.optional(z.intersection(zTimer, z.unknown().register(z.globalRegistry, {
1195
+ description: "The timer this start stopped on another task (only one runs at a time)."
1196
+ }))),
1197
+ already_running: z.optional(z.literal(true).register(z.globalRegistry, {
1198
+ description: "Only present when this task\u2019s timer was already running; nothing changed."
1199
+ }))
1200
+ });
1201
+ var zHistoryEntry = z.object({
1202
+ task_id: z.string().check(z.regex(/^[0-9a-fA-F]{3,32}$|^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/)).register(z.globalRegistry, {
1203
+ description: "The task (short id)."
1204
+ }),
1205
+ action: z.string().register(z.globalRegistry, {
1206
+ description: "What changed: `created`, `status`, `priority`, `scheduled`, `parent_added`, `parent_removed`, `title`, `description`, `encryption`."
1207
+ }),
1208
+ at: z.string().register(z.globalRegistry, {
1209
+ description: "When it changed (ISO 8601 UTC)."
1210
+ }),
1211
+ old: z.optional(z.string().register(z.globalRegistry, {
1212
+ description: "The value before. `status`: the label (e.g. `IN_PROGRESS`); `priority`: the number; `scheduled`: the deadline column id (e.g. `w-48-2026`); `title`/`description`: the text. Omitted when there was none."
1213
+ })),
1214
+ new: z.optional(z.string().register(z.globalRegistry, {
1215
+ description: "The value after, same forms as `old`. For `parent_added`/`parent_removed` it is the parent task (short id). Omitted when cleared."
1216
+ })),
1217
+ reason: z.optional(z.string().register(z.globalRegistry, {
1218
+ description: "The note given for the change (e.g. why a deadline moved)."
1219
+ })),
1220
+ actor: z.optional(z.string().register(z.globalRegistry, {
1221
+ description: "Who made it when it was not the owner in the web app: `apikey:<key prefix>` or `oauth:<app name>`. Omitted for the owner."
1222
+ })),
1223
+ encrypted: z.optional(z.literal(true).register(z.globalRegistry, {
1224
+ description: "Only on a `title`/`description` edit saved end-to-end encrypted: its text is omitted."
1225
+ }))
1226
+ });
1069
1227
  var zListTasksQuery = z.object({
1070
1228
  includeEncrypted: z.optional(z.boolean().register(z.globalRegistry, {
1071
1229
  description: "Defaults to false. In tree mode, encrypted tasks are pruned UNLESS they lie on the path to an unencrypted task \u2014 so an encrypted parent of a readable task is kept (with `encrypted: true` and no title/description keys) to preserve structure, while fully-encrypted branches are hidden. In flat mode, encrypted tasks are simply omitted. Set to true to include ALL end-to-end-encrypted tasks for full visibility."
@@ -1239,6 +1397,67 @@ var zUpdateTaskKpiPath = z.object({
1239
1397
  })
1240
1398
  });
1241
1399
  var zUpdateTaskKpiResponse = zKpiEntry;
1400
+ var zGetTimerStatusQuery = z.object({
1401
+ day_start: z.optional(z.iso.datetime().register(z.globalRegistry, {
1402
+ description: "Start of the user's day, so `worked_today` follows their time zone, e.g. `2026-11-23T00:00:00+02:00`. Defaults to midnight UTC."
1403
+ }))
1404
+ });
1405
+ var zGetTimerStatusResponse = zTimerStatus;
1406
+ var zListTimersQuery = z.object({
1407
+ task_id: z.optional(z.string().check(z.regex(/^[0-9a-fA-F]{3,32}$|^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/)).register(z.globalRegistry, {
1408
+ description: "Only this task\u2019s timers (full UUID or short id)."
1409
+ })),
1410
+ since: z.optional(z.iso.datetime().register(z.globalRegistry, {
1411
+ description: "Only timers started at or after this instant."
1412
+ })),
1413
+ limit: z.optional(z.int().check(z.gte(1), z.lte(1e3)).register(z.globalRegistry, {
1414
+ description: "Most entries to return, newest first. Defaults to 200, at most 1000."
1415
+ }))
1416
+ });
1417
+ var zListTimersResponse = z.array(zTimer).register(z.globalRegistry, {
1418
+ description: "Timers"
1419
+ });
1420
+ var zStartTaskTimerPath = z.object({
1421
+ id: z.string().check(z.regex(/^[0-9a-fA-F]{3,32}$|^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/))
1422
+ });
1423
+ var zStartTaskTimerResponse = zStartTimerResponse;
1424
+ var zStopTimerResponse = zTimer;
1425
+ var zUpdateTimerBody = z.object({
1426
+ started_at: z.optional(z.iso.datetime().register(z.globalRegistry, {
1427
+ description: "New start, ISO 8601 with `Z` or an offset."
1428
+ })),
1429
+ ended_at: z.optional(z.iso.datetime().register(z.globalRegistry, {
1430
+ description: "New end, ISO 8601 with `Z` or an offset."
1431
+ }))
1432
+ });
1433
+ var zUpdateTimerPath = z.object({
1434
+ timerId: z.uuid().register(z.globalRegistry, {
1435
+ description: "The timer id (`id` from the timer list)."
1436
+ })
1437
+ });
1438
+ var zUpdateTimerResponse = zTimer;
1439
+ var zListTasksHistoryQuery = z.object({
1440
+ since: z.optional(z.iso.datetime().register(z.globalRegistry, {
1441
+ description: "Only changes at or after this instant."
1442
+ })),
1443
+ limit: z.optional(z.int().check(z.gte(1), z.lte(1e3)).register(z.globalRegistry, {
1444
+ description: "Most entries to return, newest first. Defaults to 200, at most 1000."
1445
+ }))
1446
+ });
1447
+ var zListTasksHistoryResponse = z.array(zHistoryEntry).register(z.globalRegistry, {
1448
+ description: "History"
1449
+ });
1450
+ var zListTaskHistoryPath = z.object({
1451
+ id: z.string().check(z.regex(/^[0-9a-fA-F]{3,32}$|^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/))
1452
+ });
1453
+ var zListTaskHistoryQuery = z.object({
1454
+ limit: z.optional(z.int().check(z.gte(1), z.lte(1e3)).register(z.globalRegistry, {
1455
+ description: "Most entries to return, newest first. Defaults to 200, at most 1000."
1456
+ }))
1457
+ });
1458
+ var zListTaskHistoryResponse = z.array(zHistoryEntry).register(z.globalRegistry, {
1459
+ description: "History"
1460
+ });
1242
1461
 
1243
1462
  // src/index.ts
1244
1463
  var PerspecTask = class {
@@ -1247,6 +1466,8 @@ var PerspecTask = class {
1247
1466
  * is scoped to. Encrypted tasks are returned with `encrypted: true` and no title/description keys.
1248
1467
  */
1249
1468
  tasks;
1469
+ /** Time tracking: the running timer, the list of work sessions, start, stop and edit. */
1470
+ timers;
1250
1471
  constructor(options) {
1251
1472
  const { apiKey } = options;
1252
1473
  const client2 = createClient(
@@ -1263,6 +1484,7 @@ var PerspecTask = class {
1263
1484
  });
1264
1485
  }
1265
1486
  this.tasks = createTasksNamespace(client2);
1487
+ this.timers = createTimersNamespace(client2);
1266
1488
  }
1267
1489
  };
1268
1490
  function createTasksNamespace(client2) {
@@ -1288,6 +1510,16 @@ function createTasksNamespace(client2) {
1288
1510
  /** Unlink by the link `id` from `list`. Wraps `PullRequests.unlinkTaskPullRequest`. */
1289
1511
  unlink: (id, prId) => PullRequests.unlinkTaskPullRequest({ client: client2, path: { id, prId } })
1290
1512
  },
1513
+ /**
1514
+ * The read-only log of every change to your tasks (status, priority,
1515
+ * deadline, parents, title, description). Needs the `history:read` scope.
1516
+ */
1517
+ history: {
1518
+ /** Every change across your plaintext tasks, newest first (`{ since, limit }`). Wraps `Tasks.listTasksHistory`. */
1519
+ list: (query) => Tasks.listTasksHistory({ client: client2, query }),
1520
+ /** Every change to one task, newest first (`{ limit }`). Wraps `Tasks.listTaskHistory`. */
1521
+ get: (id, query) => Tasks.listTaskHistory({ client: client2, path: { id }, query })
1522
+ },
1291
1523
  /**
1292
1524
  * A task's KPI: `target` entries (the number to reach, optionally by a
1293
1525
  * date) and `actual` entries (readings over time). Needs the `kpis:read` /
@@ -1307,6 +1539,20 @@ function createTasksNamespace(client2) {
1307
1539
  }
1308
1540
  };
1309
1541
  }
1542
+ function createTimersNamespace(client2) {
1543
+ return {
1544
+ /** The running timer and the seconds worked today (`{ day_start }` = the user's local midnight). Wraps `Timers.getTimerStatus`. */
1545
+ status: (query) => Timers.getTimerStatus({ client: client2, query }),
1546
+ /** Work sessions, newest first (`{ task_id, since, limit }`). Wraps `Timers.listTimers`. */
1547
+ list: (query) => Timers.listTimers({ client: client2, query }),
1548
+ /** Start a timer on a task; a timer running elsewhere is stopped first. Wraps `Timers.startTaskTimer`. */
1549
+ start: (taskId) => Timers.startTaskTimer({ client: client2, path: { id: taskId } }),
1550
+ /** Stop the running timer. Wraps `Timers.stopTimer`. */
1551
+ stop: () => Timers.stopTimer({ client: client2 }),
1552
+ /** Change a finished timer's `started_at` and/or `ended_at`. Wraps `Timers.updateTimer`. */
1553
+ update: (timerId, body) => Timers.updateTimer({ client: client2, path: { timerId }, body })
1554
+ };
1555
+ }
1310
1556
  var index_default = PerspecTask;
1311
1557
  export {
1312
1558
  CLI_CLIENT_ID,
@@ -1316,6 +1562,7 @@ export {
1316
1562
  PerspecTask,
1317
1563
  PullRequests,
1318
1564
  Tasks,
1565
+ Timers,
1319
1566
  index_default as default,
1320
1567
  refreshTokens,
1321
1568
  revokeTokens,
@@ -1331,19 +1578,35 @@ export {
1331
1578
  zGetTaskPath,
1332
1579
  zGetTaskQuery,
1333
1580
  zGetTaskResponse,
1581
+ zGetTimerStatusQuery,
1582
+ zGetTimerStatusResponse,
1583
+ zHistoryEntry,
1334
1584
  zKpiEntry,
1335
1585
  zLinkTaskPullRequestBody,
1336
1586
  zLinkTaskPullRequestPath,
1337
1587
  zLinkTaskPullRequestResponse,
1338
1588
  zListKpiTasksResponse,
1589
+ zListTaskHistoryPath,
1590
+ zListTaskHistoryQuery,
1591
+ zListTaskHistoryResponse,
1339
1592
  zListTaskKpisPath,
1340
1593
  zListTaskKpisResponse,
1341
1594
  zListTaskPullRequestsPath,
1342
1595
  zListTaskPullRequestsResponse,
1596
+ zListTasksHistoryQuery,
1597
+ zListTasksHistoryResponse,
1343
1598
  zListTasksQuery,
1344
1599
  zListTasksResponse,
1600
+ zListTimersQuery,
1601
+ zListTimersResponse,
1345
1602
  zPullRequest,
1603
+ zStartTaskTimerPath,
1604
+ zStartTaskTimerResponse,
1605
+ zStartTimerResponse,
1606
+ zStopTimerResponse,
1346
1607
  zTask,
1608
+ zTimer,
1609
+ zTimerStatus,
1347
1610
  zUnlinkTaskPullRequestPath,
1348
1611
  zUnlinkTaskPullRequestResponse,
1349
1612
  zUpdateTaskBody,
@@ -1351,6 +1614,9 @@ export {
1351
1614
  zUpdateTaskKpiPath,
1352
1615
  zUpdateTaskKpiResponse,
1353
1616
  zUpdateTaskPath,
1354
- zUpdateTaskResponse
1617
+ zUpdateTaskResponse,
1618
+ zUpdateTimerBody,
1619
+ zUpdateTimerPath,
1620
+ zUpdateTimerResponse
1355
1621
  };
1356
1622
  //# sourceMappingURL=index.js.map