@perspectask/sdk 1.0.0 → 1.1.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/README.md +20 -0
- package/dist/index.cjs +169 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +347 -2
- package/dist/index.d.ts +347 -2
- package/dist/index.js +156 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -202,6 +202,24 @@ await pt.tasks.pullRequests.unlink('abc', prs![0].id);
|
|
|
202
202
|
|
|
203
203
|
Needs the PerspecTask GitHub app on the repository; `link` answers 404 with `code: "not_installed"` otherwise.
|
|
204
204
|
|
|
205
|
+
### KPIs
|
|
206
|
+
|
|
207
|
+
A task's KPI is a series of entries: `target` (the number to reach, optionally by a date) and `actual` (a reading at a moment, `at` required).
|
|
208
|
+
|
|
209
|
+
```ts
|
|
210
|
+
const { data: ids } = await pt.tasks.kpis.listTasks(); // ["abc", "9fb49"]: tasks that have KPIs
|
|
211
|
+
|
|
212
|
+
const { data: entries } = await pt.tasks.kpis.list('abc');
|
|
213
|
+
// [{ id, kind: "target" | "actual", at?, value?, encrypted? }], oldest first
|
|
214
|
+
|
|
215
|
+
await pt.tasks.kpis.create('abc', { kind: 'target', value: 100000, at: '2026-12-31T00:00:00Z' });
|
|
216
|
+
await pt.tasks.kpis.create('abc', { kind: 'actual', value: 42000, at: new Date().toISOString() });
|
|
217
|
+
await pt.tasks.kpis.update('abc', entries![0].id, { value: 120000 }); // `at: null` drops a target's date
|
|
218
|
+
await pt.tasks.kpis.delete('abc', entries![0].id);
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
Encrypted tasks are refused (403). An entry saved encrypted in the web app comes back with `encrypted: true` and no `value`.
|
|
222
|
+
|
|
205
223
|
## Scopes
|
|
206
224
|
|
|
207
225
|
API keys carry scopes that control access:
|
|
@@ -211,6 +229,8 @@ API keys carry scopes that control access:
|
|
|
211
229
|
| `tasks:read` | `list`, `get`, `pullRequests.list` |
|
|
212
230
|
| `tasks:write` | `create`, `update` (including title/description), `pullRequests.link` / `unlink` |
|
|
213
231
|
| `tasks:write:meta` | `create`, `update` everything **except** editing title/description of existing tasks, plus `pullRequests.link` / `unlink`. Built for AI agents. |
|
|
232
|
+
| `kpis:read` | `kpis.listTasks`, `kpis.list` |
|
|
233
|
+
| `kpis:write` | `kpis.create`, `kpis.update`, `kpis.delete` |
|
|
214
234
|
|
|
215
235
|
A call missing the required scope returns `403`.
|
|
216
236
|
|
package/dist/index.cjs
CHANGED
|
@@ -32,6 +32,7 @@ var index_exports = {};
|
|
|
32
32
|
__export(index_exports, {
|
|
33
33
|
CLI_CLIENT_ID: () => CLI_CLIENT_ID,
|
|
34
34
|
DEFAULT_BASE_URL: () => DEFAULT_BASE_URL,
|
|
35
|
+
Kpis: () => Kpis,
|
|
35
36
|
OAuthTokenError: () => OAuthTokenError,
|
|
36
37
|
PerspecTask: () => PerspecTask,
|
|
37
38
|
PullRequests: () => PullRequests,
|
|
@@ -42,13 +43,22 @@ __export(index_exports, {
|
|
|
42
43
|
startDeviceLogin: () => startDeviceLogin,
|
|
43
44
|
waitForDeviceLogin: () => waitForDeviceLogin,
|
|
44
45
|
zCreateTaskBody: () => zCreateTaskBody,
|
|
46
|
+
zCreateTaskKpiBody: () => zCreateTaskKpiBody,
|
|
47
|
+
zCreateTaskKpiPath: () => zCreateTaskKpiPath,
|
|
48
|
+
zCreateTaskKpiResponse: () => zCreateTaskKpiResponse,
|
|
45
49
|
zCreateTaskResponse: () => zCreateTaskResponse,
|
|
50
|
+
zDeleteTaskKpiPath: () => zDeleteTaskKpiPath,
|
|
51
|
+
zDeleteTaskKpiResponse: () => zDeleteTaskKpiResponse,
|
|
46
52
|
zGetTaskPath: () => zGetTaskPath,
|
|
47
53
|
zGetTaskQuery: () => zGetTaskQuery,
|
|
48
54
|
zGetTaskResponse: () => zGetTaskResponse,
|
|
55
|
+
zKpiEntry: () => zKpiEntry,
|
|
49
56
|
zLinkTaskPullRequestBody: () => zLinkTaskPullRequestBody,
|
|
50
57
|
zLinkTaskPullRequestPath: () => zLinkTaskPullRequestPath,
|
|
51
58
|
zLinkTaskPullRequestResponse: () => zLinkTaskPullRequestResponse,
|
|
59
|
+
zListKpiTasksResponse: () => zListKpiTasksResponse,
|
|
60
|
+
zListTaskKpisPath: () => zListTaskKpisPath,
|
|
61
|
+
zListTaskKpisResponse: () => zListTaskKpisResponse,
|
|
52
62
|
zListTaskPullRequestsPath: () => zListTaskPullRequestsPath,
|
|
53
63
|
zListTaskPullRequestsResponse: () => zListTaskPullRequestsResponse,
|
|
54
64
|
zListTasksQuery: () => zListTasksQuery,
|
|
@@ -58,6 +68,9 @@ __export(index_exports, {
|
|
|
58
68
|
zUnlinkTaskPullRequestPath: () => zUnlinkTaskPullRequestPath,
|
|
59
69
|
zUnlinkTaskPullRequestResponse: () => zUnlinkTaskPullRequestResponse,
|
|
60
70
|
zUpdateTaskBody: () => zUpdateTaskBody,
|
|
71
|
+
zUpdateTaskKpiBody: () => zUpdateTaskKpiBody,
|
|
72
|
+
zUpdateTaskKpiPath: () => zUpdateTaskKpiPath,
|
|
73
|
+
zUpdateTaskKpiResponse: () => zUpdateTaskKpiResponse,
|
|
61
74
|
zUpdateTaskPath: () => zUpdateTaskPath,
|
|
62
75
|
zUpdateTaskResponse: () => zUpdateTaskResponse
|
|
63
76
|
});
|
|
@@ -944,6 +957,74 @@ var PullRequests = class {
|
|
|
944
957
|
});
|
|
945
958
|
}
|
|
946
959
|
};
|
|
960
|
+
var Kpis = class {
|
|
961
|
+
/**
|
|
962
|
+
* List tasks with KPIs
|
|
963
|
+
*
|
|
964
|
+
* Short ids of your tasks that have KPI entries. Encrypted tasks are left out. Fetch a task with `GET /tasks/{id}` for its title.
|
|
965
|
+
*/
|
|
966
|
+
static listKpiTasks(options) {
|
|
967
|
+
return (options?.client ?? client).get({
|
|
968
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
969
|
+
url: "/kpis",
|
|
970
|
+
...options
|
|
971
|
+
});
|
|
972
|
+
}
|
|
973
|
+
/**
|
|
974
|
+
* List the KPI entries of a task
|
|
975
|
+
*
|
|
976
|
+
* The task's targets and actuals, oldest first (dateless targets first). Encrypted tasks are refused (403). An entry saved end-to-end encrypted in the web app comes back with `encrypted: true` and no `value`.
|
|
977
|
+
*/
|
|
978
|
+
static listTaskKpis(options) {
|
|
979
|
+
return (options.client ?? client).get({
|
|
980
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
981
|
+
url: "/tasks/{id}/kpis",
|
|
982
|
+
...options
|
|
983
|
+
});
|
|
984
|
+
}
|
|
985
|
+
/**
|
|
986
|
+
* Add a KPI entry to a task
|
|
987
|
+
*
|
|
988
|
+
* Add a target (the number to reach, optionally by a date) or an actual (a reading at a moment; `at` required). Encrypted tasks are refused (403). An entry saved end-to-end encrypted in the web app comes back with `encrypted: true` and no `value`.
|
|
989
|
+
*/
|
|
990
|
+
static createTaskKpi(options) {
|
|
991
|
+
return (options.client ?? client).post({
|
|
992
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
993
|
+
url: "/tasks/{id}/kpis",
|
|
994
|
+
...options,
|
|
995
|
+
headers: {
|
|
996
|
+
"Content-Type": "application/json",
|
|
997
|
+
...options.headers
|
|
998
|
+
}
|
|
999
|
+
});
|
|
1000
|
+
}
|
|
1001
|
+
/**
|
|
1002
|
+
* Delete a KPI entry
|
|
1003
|
+
*/
|
|
1004
|
+
static deleteTaskKpi(options) {
|
|
1005
|
+
return (options.client ?? client).delete({
|
|
1006
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1007
|
+
url: "/tasks/{id}/kpis/{kpiId}",
|
|
1008
|
+
...options
|
|
1009
|
+
});
|
|
1010
|
+
}
|
|
1011
|
+
/**
|
|
1012
|
+
* Update a KPI entry
|
|
1013
|
+
*
|
|
1014
|
+
* Change any of `kind`, `value` and `at`. Only the fields you send change.
|
|
1015
|
+
*/
|
|
1016
|
+
static updateTaskKpi(options) {
|
|
1017
|
+
return (options.client ?? client).patch({
|
|
1018
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1019
|
+
url: "/tasks/{id}/kpis/{kpiId}",
|
|
1020
|
+
...options,
|
|
1021
|
+
headers: {
|
|
1022
|
+
"Content-Type": "application/json",
|
|
1023
|
+
...options.headers
|
|
1024
|
+
}
|
|
1025
|
+
});
|
|
1026
|
+
}
|
|
1027
|
+
};
|
|
947
1028
|
|
|
948
1029
|
// src/oauth.ts
|
|
949
1030
|
var CLI_CLIENT_ID = "perspectask-cli";
|
|
@@ -1146,6 +1227,23 @@ var zPullRequest = z.object({
|
|
|
1146
1227
|
description: "`auto` = linked by the pt- code in the PR; `manual` = linked by URL."
|
|
1147
1228
|
})
|
|
1148
1229
|
});
|
|
1230
|
+
var zKpiEntry = z.object({
|
|
1231
|
+
id: z.uuid().register(z.globalRegistry, {
|
|
1232
|
+
description: "Id of this entry. Pass it to update or delete."
|
|
1233
|
+
}),
|
|
1234
|
+
kind: z.enum(["target", "actual"]).register(z.globalRegistry, {
|
|
1235
|
+
description: "`target` = the number you aim for (by `at`); `actual` = a reading of where it stands at `at`."
|
|
1236
|
+
}),
|
|
1237
|
+
at: z.optional(z.string().register(z.globalRegistry, {
|
|
1238
|
+
description: "ISO 8601 UTC instant. Omitted for a target with no date."
|
|
1239
|
+
})),
|
|
1240
|
+
value: z.optional(z.number().register(z.globalRegistry, {
|
|
1241
|
+
description: "The number. Omitted when the entry was saved end-to-end encrypted (then `encrypted` is true)."
|
|
1242
|
+
})),
|
|
1243
|
+
encrypted: z.optional(z.literal(true).register(z.globalRegistry, {
|
|
1244
|
+
description: "Only present when the value is end-to-end encrypted and so not readable over the API."
|
|
1245
|
+
}))
|
|
1246
|
+
});
|
|
1149
1247
|
var zListTasksQuery = z.object({
|
|
1150
1248
|
includeEncrypted: z.optional(z.boolean().register(z.globalRegistry, {
|
|
1151
1249
|
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."
|
|
@@ -1278,6 +1376,47 @@ var zUnlinkTaskPullRequestPath = z.object({
|
|
|
1278
1376
|
var zUnlinkTaskPullRequestResponse = z.void().register(z.globalRegistry, {
|
|
1279
1377
|
description: "Unlinked"
|
|
1280
1378
|
});
|
|
1379
|
+
var zListKpiTasksResponse = z.array(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, {
|
|
1380
|
+
description: "Short ids of the tasks that have KPI entries."
|
|
1381
|
+
});
|
|
1382
|
+
var zListTaskKpisPath = z.object({
|
|
1383
|
+
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}$/))
|
|
1384
|
+
});
|
|
1385
|
+
var zListTaskKpisResponse = z.array(zKpiEntry).register(z.globalRegistry, {
|
|
1386
|
+
description: "KPI entries"
|
|
1387
|
+
});
|
|
1388
|
+
var zCreateTaskKpiBody = z.object({
|
|
1389
|
+
kind: z.enum(["target", "actual"]),
|
|
1390
|
+
value: z.number(),
|
|
1391
|
+
at: z.optional(z.iso.datetime().register(z.globalRegistry, {
|
|
1392
|
+
description: "When the target is due, or when the actual was measured. Required for an actual; a target may have none."
|
|
1393
|
+
}))
|
|
1394
|
+
});
|
|
1395
|
+
var zCreateTaskKpiPath = z.object({
|
|
1396
|
+
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}$/))
|
|
1397
|
+
});
|
|
1398
|
+
var zCreateTaskKpiResponse = zKpiEntry;
|
|
1399
|
+
var zDeleteTaskKpiPath = z.object({
|
|
1400
|
+
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}$/)),
|
|
1401
|
+
kpiId: z.uuid().register(z.globalRegistry, {
|
|
1402
|
+
description: "The entry id (`id` from the KPI list)."
|
|
1403
|
+
})
|
|
1404
|
+
});
|
|
1405
|
+
var zDeleteTaskKpiResponse = z.void().register(z.globalRegistry, {
|
|
1406
|
+
description: "Deleted"
|
|
1407
|
+
});
|
|
1408
|
+
var zUpdateTaskKpiBody = z.object({
|
|
1409
|
+
kind: z.optional(z.enum(["target", "actual"])),
|
|
1410
|
+
value: z.optional(z.number()),
|
|
1411
|
+
at: z.nullish(z.iso.datetime())
|
|
1412
|
+
});
|
|
1413
|
+
var zUpdateTaskKpiPath = z.object({
|
|
1414
|
+
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}$/)),
|
|
1415
|
+
kpiId: z.uuid().register(z.globalRegistry, {
|
|
1416
|
+
description: "The entry id (`id` from the KPI list)."
|
|
1417
|
+
})
|
|
1418
|
+
});
|
|
1419
|
+
var zUpdateTaskKpiResponse = zKpiEntry;
|
|
1281
1420
|
|
|
1282
1421
|
// src/index.ts
|
|
1283
1422
|
var PerspecTask = class {
|
|
@@ -1326,6 +1465,23 @@ function createTasksNamespace(client2) {
|
|
|
1326
1465
|
link: (id, url) => PullRequests.linkTaskPullRequest({ client: client2, path: { id }, body: { url } }),
|
|
1327
1466
|
/** Unlink by the link `id` from `list`. Wraps `PullRequests.unlinkTaskPullRequest`. */
|
|
1328
1467
|
unlink: (id, prId) => PullRequests.unlinkTaskPullRequest({ client: client2, path: { id, prId } })
|
|
1468
|
+
},
|
|
1469
|
+
/**
|
|
1470
|
+
* A task's KPI: `target` entries (the number to reach, optionally by a
|
|
1471
|
+
* date) and `actual` entries (readings over time). Needs the `kpis:read` /
|
|
1472
|
+
* `kpis:write` scopes.
|
|
1473
|
+
*/
|
|
1474
|
+
kpis: {
|
|
1475
|
+
/** Short ids of the tasks that have KPI entries. Wraps `Kpis.listKpiTasks`. */
|
|
1476
|
+
listTasks: () => Kpis.listKpiTasks({ client: client2 }),
|
|
1477
|
+
/** The task's entries, oldest first. Wraps `Kpis.listTaskKpis`. */
|
|
1478
|
+
list: (id) => Kpis.listTaskKpis({ client: client2, path: { id } }),
|
|
1479
|
+
/** Add a target or an actual (`at` required for an actual). Wraps `Kpis.createTaskKpi`. */
|
|
1480
|
+
create: (id, body) => Kpis.createTaskKpi({ client: client2, path: { id }, body }),
|
|
1481
|
+
/** Change an entry's kind, value or at (`at: null` drops a target's date). Wraps `Kpis.updateTaskKpi`. */
|
|
1482
|
+
update: (id, kpiId, body) => Kpis.updateTaskKpi({ client: client2, path: { id, kpiId }, body }),
|
|
1483
|
+
/** Delete an entry by its `id` from `list`. Wraps `Kpis.deleteTaskKpi`. */
|
|
1484
|
+
delete: (id, kpiId) => Kpis.deleteTaskKpi({ client: client2, path: { id, kpiId } })
|
|
1329
1485
|
}
|
|
1330
1486
|
};
|
|
1331
1487
|
}
|
|
@@ -1334,6 +1490,7 @@ var index_default = PerspecTask;
|
|
|
1334
1490
|
0 && (module.exports = {
|
|
1335
1491
|
CLI_CLIENT_ID,
|
|
1336
1492
|
DEFAULT_BASE_URL,
|
|
1493
|
+
Kpis,
|
|
1337
1494
|
OAuthTokenError,
|
|
1338
1495
|
PerspecTask,
|
|
1339
1496
|
PullRequests,
|
|
@@ -1343,13 +1500,22 @@ var index_default = PerspecTask;
|
|
|
1343
1500
|
startDeviceLogin,
|
|
1344
1501
|
waitForDeviceLogin,
|
|
1345
1502
|
zCreateTaskBody,
|
|
1503
|
+
zCreateTaskKpiBody,
|
|
1504
|
+
zCreateTaskKpiPath,
|
|
1505
|
+
zCreateTaskKpiResponse,
|
|
1346
1506
|
zCreateTaskResponse,
|
|
1507
|
+
zDeleteTaskKpiPath,
|
|
1508
|
+
zDeleteTaskKpiResponse,
|
|
1347
1509
|
zGetTaskPath,
|
|
1348
1510
|
zGetTaskQuery,
|
|
1349
1511
|
zGetTaskResponse,
|
|
1512
|
+
zKpiEntry,
|
|
1350
1513
|
zLinkTaskPullRequestBody,
|
|
1351
1514
|
zLinkTaskPullRequestPath,
|
|
1352
1515
|
zLinkTaskPullRequestResponse,
|
|
1516
|
+
zListKpiTasksResponse,
|
|
1517
|
+
zListTaskKpisPath,
|
|
1518
|
+
zListTaskKpisResponse,
|
|
1353
1519
|
zListTaskPullRequestsPath,
|
|
1354
1520
|
zListTaskPullRequestsResponse,
|
|
1355
1521
|
zListTasksQuery,
|
|
@@ -1359,6 +1525,9 @@ var index_default = PerspecTask;
|
|
|
1359
1525
|
zUnlinkTaskPullRequestPath,
|
|
1360
1526
|
zUnlinkTaskPullRequestResponse,
|
|
1361
1527
|
zUpdateTaskBody,
|
|
1528
|
+
zUpdateTaskKpiBody,
|
|
1529
|
+
zUpdateTaskKpiPath,
|
|
1530
|
+
zUpdateTaskKpiResponse,
|
|
1362
1531
|
zUpdateTaskPath,
|
|
1363
1532
|
zUpdateTaskResponse
|
|
1364
1533
|
});
|