@perspectask/sdk 1.1.0 → 1.3.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."
@@ -1133,9 +1291,7 @@ var zGetTaskResponse = zTask;
1133
1291
  var zUpdateTaskBody = z.object({
1134
1292
  title: z.optional(z.string()),
1135
1293
  description: z.optional(z.string()),
1136
- deadline: z.optional(z.string().register(z.globalRegistry, {
1137
- description: "When this task is due \u2014 same shorthand grammar as on create (today, lifetime, q-2-2026, q2, d-20-11, \u2026)."
1138
- })),
1294
+ deadline: z.nullish(z.string()),
1139
1295
  status: z.optional(z.enum([
1140
1296
  "ACTIVE",
1141
1297
  "COMPLETED",
@@ -1239,6 +1395,67 @@ var zUpdateTaskKpiPath = z.object({
1239
1395
  })
1240
1396
  });
1241
1397
  var zUpdateTaskKpiResponse = zKpiEntry;
1398
+ var zGetTimerStatusQuery = z.object({
1399
+ day_start: z.optional(z.iso.datetime().register(z.globalRegistry, {
1400
+ 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."
1401
+ }))
1402
+ });
1403
+ var zGetTimerStatusResponse = zTimerStatus;
1404
+ var zListTimersQuery = z.object({
1405
+ 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, {
1406
+ description: "Only this task\u2019s timers (full UUID or short id)."
1407
+ })),
1408
+ since: z.optional(z.iso.datetime().register(z.globalRegistry, {
1409
+ description: "Only timers started at or after this instant."
1410
+ })),
1411
+ limit: z.optional(z.int().check(z.gte(1), z.lte(1e3)).register(z.globalRegistry, {
1412
+ description: "Most entries to return, newest first. Defaults to 200, at most 1000."
1413
+ }))
1414
+ });
1415
+ var zListTimersResponse = z.array(zTimer).register(z.globalRegistry, {
1416
+ description: "Timers"
1417
+ });
1418
+ var zStartTaskTimerPath = z.object({
1419
+ 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}$/))
1420
+ });
1421
+ var zStartTaskTimerResponse = zStartTimerResponse;
1422
+ var zStopTimerResponse = zTimer;
1423
+ var zUpdateTimerBody = z.object({
1424
+ started_at: z.optional(z.iso.datetime().register(z.globalRegistry, {
1425
+ description: "New start, ISO 8601 with `Z` or an offset."
1426
+ })),
1427
+ ended_at: z.optional(z.iso.datetime().register(z.globalRegistry, {
1428
+ description: "New end, ISO 8601 with `Z` or an offset."
1429
+ }))
1430
+ });
1431
+ var zUpdateTimerPath = z.object({
1432
+ timerId: z.uuid().register(z.globalRegistry, {
1433
+ description: "The timer id (`id` from the timer list)."
1434
+ })
1435
+ });
1436
+ var zUpdateTimerResponse = zTimer;
1437
+ var zListTasksHistoryQuery = z.object({
1438
+ since: z.optional(z.iso.datetime().register(z.globalRegistry, {
1439
+ description: "Only changes at or after this instant."
1440
+ })),
1441
+ limit: z.optional(z.int().check(z.gte(1), z.lte(1e3)).register(z.globalRegistry, {
1442
+ description: "Most entries to return, newest first. Defaults to 200, at most 1000."
1443
+ }))
1444
+ });
1445
+ var zListTasksHistoryResponse = z.array(zHistoryEntry).register(z.globalRegistry, {
1446
+ description: "History"
1447
+ });
1448
+ var zListTaskHistoryPath = z.object({
1449
+ 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}$/))
1450
+ });
1451
+ var zListTaskHistoryQuery = z.object({
1452
+ limit: z.optional(z.int().check(z.gte(1), z.lte(1e3)).register(z.globalRegistry, {
1453
+ description: "Most entries to return, newest first. Defaults to 200, at most 1000."
1454
+ }))
1455
+ });
1456
+ var zListTaskHistoryResponse = z.array(zHistoryEntry).register(z.globalRegistry, {
1457
+ description: "History"
1458
+ });
1242
1459
 
1243
1460
  // src/index.ts
1244
1461
  var PerspecTask = class {
@@ -1247,6 +1464,8 @@ var PerspecTask = class {
1247
1464
  * is scoped to. Encrypted tasks are returned with `encrypted: true` and no title/description keys.
1248
1465
  */
1249
1466
  tasks;
1467
+ /** Time tracking: the running timer, the list of work sessions, start, stop and edit. */
1468
+ timers;
1250
1469
  constructor(options) {
1251
1470
  const { apiKey } = options;
1252
1471
  const client2 = createClient(
@@ -1263,6 +1482,7 @@ var PerspecTask = class {
1263
1482
  });
1264
1483
  }
1265
1484
  this.tasks = createTasksNamespace(client2);
1485
+ this.timers = createTimersNamespace(client2);
1266
1486
  }
1267
1487
  };
1268
1488
  function createTasksNamespace(client2) {
@@ -1284,10 +1504,24 @@ function createTasksNamespace(client2) {
1284
1504
  /** List the task's linked PRs (state, checks, review, preview). Wraps `PullRequests.listTaskPullRequests`. */
1285
1505
  list: (id) => PullRequests.listTaskPullRequests({ client: client2, path: { id } }),
1286
1506
  /** Link a PR by URL (`https://github.com/o/r/pull/12` or `o/r#12`). Wraps `PullRequests.linkTaskPullRequest`. */
1287
- link: (id, url) => PullRequests.linkTaskPullRequest({ client: client2, path: { id }, body: { url } }),
1507
+ link: (id, url) => PullRequests.linkTaskPullRequest({
1508
+ client: client2,
1509
+ path: { id },
1510
+ body: { url }
1511
+ }),
1288
1512
  /** Unlink by the link `id` from `list`. Wraps `PullRequests.unlinkTaskPullRequest`. */
1289
1513
  unlink: (id, prId) => PullRequests.unlinkTaskPullRequest({ client: client2, path: { id, prId } })
1290
1514
  },
1515
+ /**
1516
+ * The read-only log of every change to your tasks (status, priority,
1517
+ * deadline, parents, title, description). Needs the `history:read` scope.
1518
+ */
1519
+ history: {
1520
+ /** Every change across your plaintext tasks, newest first (`{ since, limit }`). Wraps `Tasks.listTasksHistory`. */
1521
+ list: (query) => Tasks.listTasksHistory({ client: client2, query }),
1522
+ /** Every change to one task, newest first (`{ limit }`). Wraps `Tasks.listTaskHistory`. */
1523
+ get: (id, query) => Tasks.listTaskHistory({ client: client2, path: { id }, query })
1524
+ },
1291
1525
  /**
1292
1526
  * A task's KPI: `target` entries (the number to reach, optionally by a
1293
1527
  * date) and `actual` entries (readings over time). Needs the `kpis:read` /
@@ -1307,6 +1541,20 @@ function createTasksNamespace(client2) {
1307
1541
  }
1308
1542
  };
1309
1543
  }
1544
+ function createTimersNamespace(client2) {
1545
+ return {
1546
+ /** The running timer and the seconds worked today (`{ day_start }` = the user's local midnight). Wraps `Timers.getTimerStatus`. */
1547
+ status: (query) => Timers.getTimerStatus({ client: client2, query }),
1548
+ /** Work sessions, newest first (`{ task_id, since, limit }`). Wraps `Timers.listTimers`. */
1549
+ list: (query) => Timers.listTimers({ client: client2, query }),
1550
+ /** Start a timer on a task; a timer running elsewhere is stopped first. Wraps `Timers.startTaskTimer`. */
1551
+ start: (taskId) => Timers.startTaskTimer({ client: client2, path: { id: taskId } }),
1552
+ /** Stop the running timer. Wraps `Timers.stopTimer`. */
1553
+ stop: () => Timers.stopTimer({ client: client2 }),
1554
+ /** Change a finished timer's `started_at` and/or `ended_at`. Wraps `Timers.updateTimer`. */
1555
+ update: (timerId, body) => Timers.updateTimer({ client: client2, path: { timerId }, body })
1556
+ };
1557
+ }
1310
1558
  var index_default = PerspecTask;
1311
1559
  export {
1312
1560
  CLI_CLIENT_ID,
@@ -1316,6 +1564,7 @@ export {
1316
1564
  PerspecTask,
1317
1565
  PullRequests,
1318
1566
  Tasks,
1567
+ Timers,
1319
1568
  index_default as default,
1320
1569
  refreshTokens,
1321
1570
  revokeTokens,
@@ -1331,19 +1580,35 @@ export {
1331
1580
  zGetTaskPath,
1332
1581
  zGetTaskQuery,
1333
1582
  zGetTaskResponse,
1583
+ zGetTimerStatusQuery,
1584
+ zGetTimerStatusResponse,
1585
+ zHistoryEntry,
1334
1586
  zKpiEntry,
1335
1587
  zLinkTaskPullRequestBody,
1336
1588
  zLinkTaskPullRequestPath,
1337
1589
  zLinkTaskPullRequestResponse,
1338
1590
  zListKpiTasksResponse,
1591
+ zListTaskHistoryPath,
1592
+ zListTaskHistoryQuery,
1593
+ zListTaskHistoryResponse,
1339
1594
  zListTaskKpisPath,
1340
1595
  zListTaskKpisResponse,
1341
1596
  zListTaskPullRequestsPath,
1342
1597
  zListTaskPullRequestsResponse,
1598
+ zListTasksHistoryQuery,
1599
+ zListTasksHistoryResponse,
1343
1600
  zListTasksQuery,
1344
1601
  zListTasksResponse,
1602
+ zListTimersQuery,
1603
+ zListTimersResponse,
1345
1604
  zPullRequest,
1605
+ zStartTaskTimerPath,
1606
+ zStartTaskTimerResponse,
1607
+ zStartTimerResponse,
1608
+ zStopTimerResponse,
1346
1609
  zTask,
1610
+ zTimer,
1611
+ zTimerStatus,
1347
1612
  zUnlinkTaskPullRequestPath,
1348
1613
  zUnlinkTaskPullRequestResponse,
1349
1614
  zUpdateTaskBody,
@@ -1351,6 +1616,9 @@ export {
1351
1616
  zUpdateTaskKpiPath,
1352
1617
  zUpdateTaskKpiResponse,
1353
1618
  zUpdateTaskPath,
1354
- zUpdateTaskResponse
1619
+ zUpdateTaskResponse,
1620
+ zUpdateTimerBody,
1621
+ zUpdateTimerPath,
1622
+ zUpdateTimerResponse
1355
1623
  };
1356
1624
  //# sourceMappingURL=index.js.map