@perspectask/sdk 0.0.5 → 0.0.6
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 -3
- package/dist/index.cjs +136 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +292 -1
- package/dist/index.d.ts +292 -1
- package/dist/index.js +127 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -185,15 +185,32 @@ await pt.tasks.update('<child-id>', {
|
|
|
185
185
|
});
|
|
186
186
|
```
|
|
187
187
|
|
|
188
|
+
### Pull requests
|
|
189
|
+
|
|
190
|
+
A GitHub PR whose branch name or title contains the task's `pr_token` (returned by `tasks.get`, `create` and `update`, e.g. `pt-a3f91c2`) links itself to the task. These methods cover the rest:
|
|
191
|
+
|
|
192
|
+
```ts
|
|
193
|
+
const { data: task } = await pt.tasks.get('abc');
|
|
194
|
+
console.log(task?.pr_token); // "pt-abc12f4" — put it in the branch or PR title
|
|
195
|
+
|
|
196
|
+
const { data: prs } = await pt.tasks.pullRequests.list('abc');
|
|
197
|
+
// [{ id, repo, number, title, url, state, checks?, review?, preview_url?, draft?, linked_by }]
|
|
198
|
+
|
|
199
|
+
await pt.tasks.pullRequests.link('abc', 'https://github.com/owner/repo/pull/12'); // or 'owner/repo#12'
|
|
200
|
+
await pt.tasks.pullRequests.unlink('abc', prs![0].id);
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
Needs the PerspecTask GitHub app on the repository; `link` answers 404 with `code: "not_installed"` otherwise.
|
|
204
|
+
|
|
188
205
|
## Scopes
|
|
189
206
|
|
|
190
207
|
API keys carry scopes that control access:
|
|
191
208
|
|
|
192
209
|
| Scope | Allows |
|
|
193
210
|
| ------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
194
|
-
| `tasks:read` | `list`, `get`
|
|
195
|
-
| `tasks:write` | `create`, `update` (including title/description)
|
|
196
|
-
| `tasks:write:meta` | `create`, `update` everything **except** editing title/description of existing tasks. Built for AI agents
|
|
211
|
+
| `tasks:read` | `list`, `get`, `pullRequests.list` |
|
|
212
|
+
| `tasks:write` | `create`, `update` (including title/description), `pullRequests.link` / `unlink` |
|
|
213
|
+
| `tasks:write:meta` | `create`, `update` everything **except** editing title/description of existing tasks, plus `pullRequests.link` / `unlink`. Built for AI agents. |
|
|
197
214
|
|
|
198
215
|
A call missing the required scope returns `403`.
|
|
199
216
|
|
package/dist/index.cjs
CHANGED
|
@@ -31,6 +31,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
33
|
PerspecTask: () => PerspecTask,
|
|
34
|
+
PullRequests: () => PullRequests,
|
|
34
35
|
Tasks: () => Tasks,
|
|
35
36
|
default: () => index_default,
|
|
36
37
|
zCreateTaskBody: () => zCreateTaskBody,
|
|
@@ -38,9 +39,17 @@ __export(index_exports, {
|
|
|
38
39
|
zGetTaskPath: () => zGetTaskPath,
|
|
39
40
|
zGetTaskQuery: () => zGetTaskQuery,
|
|
40
41
|
zGetTaskResponse: () => zGetTaskResponse,
|
|
42
|
+
zLinkTaskPullRequestBody: () => zLinkTaskPullRequestBody,
|
|
43
|
+
zLinkTaskPullRequestPath: () => zLinkTaskPullRequestPath,
|
|
44
|
+
zLinkTaskPullRequestResponse: () => zLinkTaskPullRequestResponse,
|
|
45
|
+
zListTaskPullRequestsPath: () => zListTaskPullRequestsPath,
|
|
46
|
+
zListTaskPullRequestsResponse: () => zListTaskPullRequestsResponse,
|
|
41
47
|
zListTasksQuery: () => zListTasksQuery,
|
|
42
48
|
zListTasksResponse: () => zListTasksResponse,
|
|
49
|
+
zPullRequest: () => zPullRequest,
|
|
43
50
|
zTask: () => zTask,
|
|
51
|
+
zUnlinkTaskPullRequestPath: () => zUnlinkTaskPullRequestPath,
|
|
52
|
+
zUnlinkTaskPullRequestResponse: () => zUnlinkTaskPullRequestResponse,
|
|
44
53
|
zUpdateTaskBody: () => zUpdateTaskBody,
|
|
45
54
|
zUpdateTaskPath: () => zUpdateTaskPath,
|
|
46
55
|
zUpdateTaskResponse: () => zUpdateTaskResponse
|
|
@@ -886,6 +895,48 @@ var Tasks = class {
|
|
|
886
895
|
});
|
|
887
896
|
}
|
|
888
897
|
};
|
|
898
|
+
var PullRequests = class {
|
|
899
|
+
/**
|
|
900
|
+
* List pull requests linked to a task
|
|
901
|
+
*
|
|
902
|
+
* The GitHub pull requests linked to this task, with their state, CI result, review decision and preview deploy, kept up to date by GitHub webhooks. Needs the PerspecTask GitHub app installed on the repository (Account → GitHub in the web app).
|
|
903
|
+
*/
|
|
904
|
+
static listTaskPullRequests(options) {
|
|
905
|
+
return (options.client ?? client).get({
|
|
906
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
907
|
+
url: "/tasks/{id}/pull-requests",
|
|
908
|
+
...options
|
|
909
|
+
});
|
|
910
|
+
}
|
|
911
|
+
/**
|
|
912
|
+
* Link a pull request to a task
|
|
913
|
+
*
|
|
914
|
+
* Link a PR by its URL. Usually unnecessary: a PR whose title, branch or description contains the task's `pr_token` links itself. Linking an already-linked PR refreshes it. Needs the PerspecTask GitHub app installed on the repository (Account → GitHub in the web app). Answers 404 with `code: "not_installed"` when the app isn't on that repository or your GitHub account can't read it.
|
|
915
|
+
*/
|
|
916
|
+
static linkTaskPullRequest(options) {
|
|
917
|
+
return (options.client ?? client).post({
|
|
918
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
919
|
+
url: "/tasks/{id}/pull-requests",
|
|
920
|
+
...options,
|
|
921
|
+
headers: {
|
|
922
|
+
"Content-Type": "application/json",
|
|
923
|
+
...options.headers
|
|
924
|
+
}
|
|
925
|
+
});
|
|
926
|
+
}
|
|
927
|
+
/**
|
|
928
|
+
* Unlink a pull request from a task
|
|
929
|
+
*
|
|
930
|
+
* Remove a link (`prId` is the `id` from the list). It stays unlinked: later pushes to the PR do not link it again, only linking it by URL does.
|
|
931
|
+
*/
|
|
932
|
+
static unlinkTaskPullRequest(options) {
|
|
933
|
+
return (options.client ?? client).delete({
|
|
934
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
935
|
+
url: "/tasks/{id}/pull-requests/{prId}",
|
|
936
|
+
...options
|
|
937
|
+
});
|
|
938
|
+
}
|
|
939
|
+
};
|
|
889
940
|
|
|
890
941
|
// src/generated/zod.gen.ts
|
|
891
942
|
var z = __toESM(require("zod/mini"), 1);
|
|
@@ -893,6 +944,9 @@ var zTask = z.object({
|
|
|
893
944
|
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, {
|
|
894
945
|
description: 'Short id: the minimum unique prefix of the task UUID (e.g. "a3f"). Accepted anywhere an id is.'
|
|
895
946
|
})),
|
|
947
|
+
pr_token: z.optional(z.string().check(z.regex(/^pt-[0-9a-f]{7,32}$/)).register(z.globalRegistry, {
|
|
948
|
+
description: 'Put this code (e.g. "pt-a3f91c2") in a GitHub pull request title or branch name and the PR links itself to this task (needs the PerspecTask GitHub app on the repo). It is longer than the short id on purpose, so it stays unambiguous as more tasks are added. Returned on single-task responses (get, create, update), not on lists.'
|
|
949
|
+
})),
|
|
896
950
|
title: z.optional(z.string()),
|
|
897
951
|
description: z.optional(z.string()),
|
|
898
952
|
encrypted: z.optional(z.boolean().register(z.globalRegistry, {
|
|
@@ -933,6 +987,41 @@ var zTask = z.object({
|
|
|
933
987
|
children: z.optional(z.array(z.union([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}$/)), z.lazy(() => zTask)]))),
|
|
934
988
|
parents: z.optional(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}$/))))
|
|
935
989
|
});
|
|
990
|
+
var zPullRequest = z.object({
|
|
991
|
+
id: z.uuid().register(z.globalRegistry, {
|
|
992
|
+
description: "Id of this task\u2194PR link. Pass it to unlink."
|
|
993
|
+
}),
|
|
994
|
+
repo: z.string(),
|
|
995
|
+
number: z.int(),
|
|
996
|
+
title: z.string(),
|
|
997
|
+
url: z.string().register(z.globalRegistry, {
|
|
998
|
+
description: "The PR on github.com."
|
|
999
|
+
}),
|
|
1000
|
+
state: z.enum([
|
|
1001
|
+
"open",
|
|
1002
|
+
"closed",
|
|
1003
|
+
"merged"
|
|
1004
|
+
]),
|
|
1005
|
+
draft: z.optional(z.literal(true).register(z.globalRegistry, {
|
|
1006
|
+
description: "Only present when the PR is a draft."
|
|
1007
|
+
})),
|
|
1008
|
+
checks: z.optional(z.enum([
|
|
1009
|
+
"pending",
|
|
1010
|
+
"success",
|
|
1011
|
+
"failure"
|
|
1012
|
+
]).register(z.globalRegistry, {
|
|
1013
|
+
description: "Combined CI result of the PR's head commit (check runs + commit statuses). Omitted when the commit has no CI."
|
|
1014
|
+
})),
|
|
1015
|
+
review: z.optional(z.enum(["approved", "changes_requested"]).register(z.globalRegistry, {
|
|
1016
|
+
description: "Reviewers' current decision. Omitted when nobody approved or requested changes."
|
|
1017
|
+
})),
|
|
1018
|
+
preview_url: z.optional(z.string().register(z.globalRegistry, {
|
|
1019
|
+
description: "Latest successful preview deployment (Vercel, Netlify, \u2026). Omitted when there is none."
|
|
1020
|
+
})),
|
|
1021
|
+
linked_by: z.enum(["auto", "manual"]).register(z.globalRegistry, {
|
|
1022
|
+
description: "`auto` = linked by the pt- code in the PR; `manual` = linked by URL."
|
|
1023
|
+
})
|
|
1024
|
+
});
|
|
936
1025
|
var zListTasksQuery = z.object({
|
|
937
1026
|
includeEncrypted: z.optional(z.boolean().register(z.globalRegistry, {
|
|
938
1027
|
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."
|
|
@@ -1041,6 +1130,30 @@ var zUpdateTaskPath = z.object({
|
|
|
1041
1130
|
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}$/))
|
|
1042
1131
|
});
|
|
1043
1132
|
var zUpdateTaskResponse = zTask;
|
|
1133
|
+
var zListTaskPullRequestsPath = z.object({
|
|
1134
|
+
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}$/))
|
|
1135
|
+
});
|
|
1136
|
+
var zListTaskPullRequestsResponse = z.array(zPullRequest).register(z.globalRegistry, {
|
|
1137
|
+
description: "Linked pull requests (oldest first)"
|
|
1138
|
+
});
|
|
1139
|
+
var zLinkTaskPullRequestBody = z.object({
|
|
1140
|
+
url: z.string().check(z.minLength(1)).register(z.globalRegistry, {
|
|
1141
|
+
description: "The pull request: `https://github.com/owner/repo/pull/123` or `owner/repo#123`."
|
|
1142
|
+
})
|
|
1143
|
+
});
|
|
1144
|
+
var zLinkTaskPullRequestPath = z.object({
|
|
1145
|
+
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}$/))
|
|
1146
|
+
});
|
|
1147
|
+
var zLinkTaskPullRequestResponse = zPullRequest;
|
|
1148
|
+
var zUnlinkTaskPullRequestPath = z.object({
|
|
1149
|
+
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}$/)),
|
|
1150
|
+
prId: z.uuid().register(z.globalRegistry, {
|
|
1151
|
+
description: "The link id (`id` from the pull request list)."
|
|
1152
|
+
})
|
|
1153
|
+
});
|
|
1154
|
+
var zUnlinkTaskPullRequestResponse = z.void().register(z.globalRegistry, {
|
|
1155
|
+
description: "Unlinked"
|
|
1156
|
+
});
|
|
1044
1157
|
|
|
1045
1158
|
// src/index.ts
|
|
1046
1159
|
var PerspecTask = class {
|
|
@@ -1070,22 +1183,44 @@ function createTasksNamespace(client2) {
|
|
|
1070
1183
|
/** Create a task (`title` required). Wraps `Tasks.createTask`. */
|
|
1071
1184
|
create: (body) => Tasks.createTask({ client: client2, body }),
|
|
1072
1185
|
/** Update editable fields on a task by id. Wraps `Tasks.updateTask`. */
|
|
1073
|
-
update: (id, body) => Tasks.updateTask({ client: client2, path: { id }, body })
|
|
1186
|
+
update: (id, body) => Tasks.updateTask({ client: client2, path: { id }, body }),
|
|
1187
|
+
/**
|
|
1188
|
+
* GitHub pull requests linked to a task. Usually you don't need these: put
|
|
1189
|
+
* the task's `pr_token` (e.g. `pt-a3f91c2`, on `tasks.get`) in a PR title
|
|
1190
|
+
* or branch name and the PR links itself.
|
|
1191
|
+
*/
|
|
1192
|
+
pullRequests: {
|
|
1193
|
+
/** List the task's linked PRs (state, checks, review, preview). Wraps `PullRequests.listTaskPullRequests`. */
|
|
1194
|
+
list: (id) => PullRequests.listTaskPullRequests({ client: client2, path: { id } }),
|
|
1195
|
+
/** Link a PR by URL (`https://github.com/o/r/pull/12` or `o/r#12`). Wraps `PullRequests.linkTaskPullRequest`. */
|
|
1196
|
+
link: (id, url) => PullRequests.linkTaskPullRequest({ client: client2, path: { id }, body: { url } }),
|
|
1197
|
+
/** Unlink by the link `id` from `list`. Wraps `PullRequests.unlinkTaskPullRequest`. */
|
|
1198
|
+
unlink: (id, prId) => PullRequests.unlinkTaskPullRequest({ client: client2, path: { id, prId } })
|
|
1199
|
+
}
|
|
1074
1200
|
};
|
|
1075
1201
|
}
|
|
1076
1202
|
var index_default = PerspecTask;
|
|
1077
1203
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1078
1204
|
0 && (module.exports = {
|
|
1079
1205
|
PerspecTask,
|
|
1206
|
+
PullRequests,
|
|
1080
1207
|
Tasks,
|
|
1081
1208
|
zCreateTaskBody,
|
|
1082
1209
|
zCreateTaskResponse,
|
|
1083
1210
|
zGetTaskPath,
|
|
1084
1211
|
zGetTaskQuery,
|
|
1085
1212
|
zGetTaskResponse,
|
|
1213
|
+
zLinkTaskPullRequestBody,
|
|
1214
|
+
zLinkTaskPullRequestPath,
|
|
1215
|
+
zLinkTaskPullRequestResponse,
|
|
1216
|
+
zListTaskPullRequestsPath,
|
|
1217
|
+
zListTaskPullRequestsResponse,
|
|
1086
1218
|
zListTasksQuery,
|
|
1087
1219
|
zListTasksResponse,
|
|
1220
|
+
zPullRequest,
|
|
1088
1221
|
zTask,
|
|
1222
|
+
zUnlinkTaskPullRequestPath,
|
|
1223
|
+
zUnlinkTaskPullRequestResponse,
|
|
1089
1224
|
zUpdateTaskBody,
|
|
1090
1225
|
zUpdateTaskPath,
|
|
1091
1226
|
zUpdateTaskResponse
|