@perspectask/sdk 0.0.5 → 0.0.7

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.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import * as z from 'zod/mini';
2
+ export { C as CLI_CLIENT_ID, a as DEFAULT_BASE_URL, D as DeviceLogin, b as OAuthRequestOptions, c as OAuthTokenError, O as OAuthTokens, r as refreshTokens, d as revokeTokens, s as startDeviceLogin, w as waitForDeviceLogin } from './oauth-kp6GpoOV.js';
2
3
 
3
4
  type AuthToken = string | undefined;
4
5
  interface Auth {
@@ -322,6 +323,10 @@ type Task = {
322
323
  * Short id: the minimum unique prefix of the task UUID (e.g. "a3f"). Accepted anywhere an id is.
323
324
  */
324
325
  id?: string;
326
+ /**
327
+ * 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.
328
+ */
329
+ pr_token?: string;
325
330
  title?: string;
326
331
  description?: string;
327
332
  /**
@@ -357,6 +362,44 @@ type Task = {
357
362
  children?: Array<string | Task>;
358
363
  parents?: Array<string>;
359
364
  };
365
+ type PullRequest = {
366
+ /**
367
+ * Id of this task↔PR link. Pass it to unlink.
368
+ */
369
+ id: string;
370
+ repo: string;
371
+ number: number;
372
+ title: string;
373
+ /**
374
+ * The PR on github.com.
375
+ */
376
+ url: string;
377
+ state: 'open' | 'closed' | 'merged';
378
+ /**
379
+ * Only present when the PR is a draft.
380
+ */
381
+ draft?: true;
382
+ /**
383
+ * Combined CI result of the PR's head commit (check runs + commit statuses). Omitted when the commit has no CI.
384
+ */
385
+ checks?: 'pending' | 'success' | 'failure';
386
+ /**
387
+ * Reviewers' current decision. Omitted when nobody approved or requested changes.
388
+ */
389
+ review?: 'approved' | 'changes_requested';
390
+ /**
391
+ * Latest successful preview deployment (Vercel, Netlify, …). Omitted when there is none.
392
+ */
393
+ preview_url?: string;
394
+ /**
395
+ * State of the preview deploy of the PR's head commit: `building` while it deploys, `ready` when it's live, `failed` when it broke. `preview_url` stays the last successful preview meanwhile. Omitted when no deploy was seen for that commit.
396
+ */
397
+ preview_status?: 'building' | 'ready' | 'failed';
398
+ /**
399
+ * `auto` = linked by the pt- code in the PR; `manual` = linked by URL.
400
+ */
401
+ linked_by: 'auto' | 'manual';
402
+ };
360
403
  type ListTasksData = {
361
404
  body?: never;
362
405
  path?: never;
@@ -523,6 +566,90 @@ type UpdateTaskResponses = {
523
566
  200: Task;
524
567
  };
525
568
  type UpdateTaskResponse = UpdateTaskResponses[keyof UpdateTaskResponses];
569
+ type ListTaskPullRequestsData = {
570
+ body?: never;
571
+ path: {
572
+ id: string;
573
+ };
574
+ query?: never;
575
+ url: '/tasks/{id}/pull-requests';
576
+ };
577
+ type ListTaskPullRequestsErrors = {
578
+ /**
579
+ * Task not found
580
+ */
581
+ 404: unknown;
582
+ };
583
+ type ListTaskPullRequestsResponses = {
584
+ /**
585
+ * Linked pull requests (oldest first)
586
+ */
587
+ 200: Array<PullRequest>;
588
+ };
589
+ type ListTaskPullRequestsResponse = ListTaskPullRequestsResponses[keyof ListTaskPullRequestsResponses];
590
+ type LinkTaskPullRequestData = {
591
+ body: {
592
+ /**
593
+ * The pull request: `https://github.com/owner/repo/pull/123` or `owner/repo#123`.
594
+ */
595
+ url: string;
596
+ };
597
+ path: {
598
+ id: string;
599
+ };
600
+ query?: never;
601
+ url: '/tasks/{id}/pull-requests';
602
+ };
603
+ type LinkTaskPullRequestErrors = {
604
+ /**
605
+ * Not a GitHub pull request URL
606
+ */
607
+ 400: unknown;
608
+ /**
609
+ * Task is encrypted
610
+ */
611
+ 403: unknown;
612
+ /**
613
+ * Task, repository access, or pull request not found
614
+ */
615
+ 404: unknown;
616
+ };
617
+ type LinkTaskPullRequestResponses = {
618
+ /**
619
+ * Linked
620
+ */
621
+ 201: PullRequest;
622
+ };
623
+ type LinkTaskPullRequestResponse = LinkTaskPullRequestResponses[keyof LinkTaskPullRequestResponses];
624
+ type UnlinkTaskPullRequestData = {
625
+ body?: never;
626
+ path: {
627
+ id: string;
628
+ /**
629
+ * The link id (`id` from the pull request list).
630
+ */
631
+ prId: string;
632
+ };
633
+ query?: never;
634
+ url: '/tasks/{id}/pull-requests/{prId}';
635
+ };
636
+ type UnlinkTaskPullRequestErrors = {
637
+ /**
638
+ * Task is encrypted
639
+ */
640
+ 403: unknown;
641
+ /**
642
+ * Task or link not found
643
+ */
644
+ 404: unknown;
645
+ };
646
+ type UnlinkTaskPullRequestResponses = {
647
+ /**
648
+ * Unlinked
649
+ */
650
+ 204: void;
651
+ };
652
+ type UnlinkTaskPullRequestResponse = UnlinkTaskPullRequestResponses[keyof UnlinkTaskPullRequestResponses];
526
653
 
527
654
  type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean, TResponse = unknown> = Options$1<TData, ThrowOnError, TResponse> & {
528
655
  /**
@@ -555,9 +682,30 @@ declare class Tasks {
555
682
  */
556
683
  static updateTask<ThrowOnError extends boolean = false>(options: Options<UpdateTaskData, ThrowOnError>): RequestResult<UpdateTaskResponses, UpdateTaskErrors, ThrowOnError, "fields">;
557
684
  }
685
+ declare class PullRequests {
686
+ /**
687
+ * List pull requests linked to a task
688
+ *
689
+ * 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).
690
+ */
691
+ static listTaskPullRequests<ThrowOnError extends boolean = false>(options: Options<ListTaskPullRequestsData, ThrowOnError>): RequestResult<ListTaskPullRequestsResponses, ListTaskPullRequestsErrors, ThrowOnError, "fields">;
692
+ /**
693
+ * Link a pull request to a task
694
+ *
695
+ * 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.
696
+ */
697
+ static linkTaskPullRequest<ThrowOnError extends boolean = false>(options: Options<LinkTaskPullRequestData, ThrowOnError>): RequestResult<LinkTaskPullRequestResponses, LinkTaskPullRequestErrors, ThrowOnError, "fields">;
698
+ /**
699
+ * Unlink a pull request from a task
700
+ *
701
+ * 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.
702
+ */
703
+ static unlinkTaskPullRequest<ThrowOnError extends boolean = false>(options: Options<UnlinkTaskPullRequestData, ThrowOnError>): RequestResult<UnlinkTaskPullRequestResponses, UnlinkTaskPullRequestErrors, ThrowOnError, "fields">;
704
+ }
558
705
 
559
706
  declare const zTask: z.ZodMiniObject<{
560
707
  id: z.ZodMiniOptional<z.ZodMiniString<string>>;
708
+ pr_token: z.ZodMiniOptional<z.ZodMiniString<string>>;
561
709
  title: z.ZodMiniOptional<z.ZodMiniString<string>>;
562
710
  description: z.ZodMiniOptional<z.ZodMiniString<string>>;
563
711
  encrypted: z.ZodMiniOptional<z.ZodMiniBoolean<boolean>>;
@@ -580,6 +728,38 @@ declare const zTask: z.ZodMiniObject<{
580
728
  children: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniLazy<any>]>>>;
581
729
  parents: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
582
730
  }, z.core.$strip>;
731
+ declare const zPullRequest: z.ZodMiniObject<{
732
+ id: z.ZodMiniUUID;
733
+ repo: z.ZodMiniString<string>;
734
+ number: z.ZodMiniNumberFormat;
735
+ title: z.ZodMiniString<string>;
736
+ url: z.ZodMiniString<string>;
737
+ state: z.ZodMiniEnum<{
738
+ open: "open";
739
+ closed: "closed";
740
+ merged: "merged";
741
+ }>;
742
+ draft: z.ZodMiniOptional<z.ZodMiniLiteral<true>>;
743
+ checks: z.ZodMiniOptional<z.ZodMiniEnum<{
744
+ pending: "pending";
745
+ success: "success";
746
+ failure: "failure";
747
+ }>>;
748
+ review: z.ZodMiniOptional<z.ZodMiniEnum<{
749
+ approved: "approved";
750
+ changes_requested: "changes_requested";
751
+ }>>;
752
+ preview_url: z.ZodMiniOptional<z.ZodMiniString<string>>;
753
+ preview_status: z.ZodMiniOptional<z.ZodMiniEnum<{
754
+ building: "building";
755
+ ready: "ready";
756
+ failed: "failed";
757
+ }>>;
758
+ linked_by: z.ZodMiniEnum<{
759
+ auto: "auto";
760
+ manual: "manual";
761
+ }>;
762
+ }, z.core.$strip>;
583
763
  declare const zListTasksQuery: z.ZodMiniObject<{
584
764
  includeEncrypted: z.ZodMiniOptional<z.ZodMiniBoolean<boolean>>;
585
765
  tree: z.ZodMiniOptional<z.ZodMiniBoolean<boolean>>;
@@ -593,6 +773,7 @@ declare const zListTasksQuery: z.ZodMiniObject<{
593
773
  */
594
774
  declare const zListTasksResponse: z.ZodMiniArray<z.ZodMiniObject<{
595
775
  id: z.ZodMiniOptional<z.ZodMiniString<string>>;
776
+ pr_token: z.ZodMiniOptional<z.ZodMiniString<string>>;
596
777
  title: z.ZodMiniOptional<z.ZodMiniString<string>>;
597
778
  description: z.ZodMiniOptional<z.ZodMiniString<string>>;
598
779
  encrypted: z.ZodMiniOptional<z.ZodMiniBoolean<boolean>>;
@@ -627,6 +808,7 @@ declare const zCreateTaskBody: z.ZodMiniObject<{
627
808
  */
628
809
  declare const zCreateTaskResponse: z.ZodMiniObject<{
629
810
  id: z.ZodMiniOptional<z.ZodMiniString<string>>;
811
+ pr_token: z.ZodMiniOptional<z.ZodMiniString<string>>;
630
812
  title: z.ZodMiniOptional<z.ZodMiniString<string>>;
631
813
  description: z.ZodMiniOptional<z.ZodMiniString<string>>;
632
814
  encrypted: z.ZodMiniOptional<z.ZodMiniBoolean<boolean>>;
@@ -665,6 +847,7 @@ declare const zGetTaskQuery: z.ZodMiniObject<{
665
847
  */
666
848
  declare const zGetTaskResponse: z.ZodMiniObject<{
667
849
  id: z.ZodMiniOptional<z.ZodMiniString<string>>;
850
+ pr_token: z.ZodMiniOptional<z.ZodMiniString<string>>;
668
851
  title: z.ZodMiniOptional<z.ZodMiniString<string>>;
669
852
  description: z.ZodMiniOptional<z.ZodMiniString<string>>;
670
853
  encrypted: z.ZodMiniOptional<z.ZodMiniBoolean<boolean>>;
@@ -716,6 +899,7 @@ declare const zUpdateTaskPath: z.ZodMiniObject<{
716
899
  */
717
900
  declare const zUpdateTaskResponse: z.ZodMiniObject<{
718
901
  id: z.ZodMiniOptional<z.ZodMiniString<string>>;
902
+ pr_token: z.ZodMiniOptional<z.ZodMiniString<string>>;
719
903
  title: z.ZodMiniOptional<z.ZodMiniString<string>>;
720
904
  description: z.ZodMiniOptional<z.ZodMiniString<string>>;
721
905
  encrypted: z.ZodMiniOptional<z.ZodMiniBoolean<boolean>>;
@@ -738,18 +922,114 @@ declare const zUpdateTaskResponse: z.ZodMiniObject<{
738
922
  children: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniUnion<readonly [z.ZodMiniString<string>, z.ZodMiniLazy<any>]>>>;
739
923
  parents: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
740
924
  }, z.core.$strip>;
925
+ declare const zListTaskPullRequestsPath: z.ZodMiniObject<{
926
+ id: z.ZodMiniString<string>;
927
+ }, z.core.$strip>;
928
+ /**
929
+ * Linked pull requests (oldest first)
930
+ */
931
+ declare const zListTaskPullRequestsResponse: z.ZodMiniArray<z.ZodMiniObject<{
932
+ id: z.ZodMiniUUID;
933
+ repo: z.ZodMiniString<string>;
934
+ number: z.ZodMiniNumberFormat;
935
+ title: z.ZodMiniString<string>;
936
+ url: z.ZodMiniString<string>;
937
+ state: z.ZodMiniEnum<{
938
+ open: "open";
939
+ closed: "closed";
940
+ merged: "merged";
941
+ }>;
942
+ draft: z.ZodMiniOptional<z.ZodMiniLiteral<true>>;
943
+ checks: z.ZodMiniOptional<z.ZodMiniEnum<{
944
+ pending: "pending";
945
+ success: "success";
946
+ failure: "failure";
947
+ }>>;
948
+ review: z.ZodMiniOptional<z.ZodMiniEnum<{
949
+ approved: "approved";
950
+ changes_requested: "changes_requested";
951
+ }>>;
952
+ preview_url: z.ZodMiniOptional<z.ZodMiniString<string>>;
953
+ preview_status: z.ZodMiniOptional<z.ZodMiniEnum<{
954
+ building: "building";
955
+ ready: "ready";
956
+ failed: "failed";
957
+ }>>;
958
+ linked_by: z.ZodMiniEnum<{
959
+ auto: "auto";
960
+ manual: "manual";
961
+ }>;
962
+ }, z.core.$strip>>;
963
+ declare const zLinkTaskPullRequestBody: z.ZodMiniObject<{
964
+ url: z.ZodMiniString<string>;
965
+ }, z.core.$strip>;
966
+ declare const zLinkTaskPullRequestPath: z.ZodMiniObject<{
967
+ id: z.ZodMiniString<string>;
968
+ }, z.core.$strip>;
969
+ /**
970
+ * Linked
971
+ */
972
+ declare const zLinkTaskPullRequestResponse: z.ZodMiniObject<{
973
+ id: z.ZodMiniUUID;
974
+ repo: z.ZodMiniString<string>;
975
+ number: z.ZodMiniNumberFormat;
976
+ title: z.ZodMiniString<string>;
977
+ url: z.ZodMiniString<string>;
978
+ state: z.ZodMiniEnum<{
979
+ open: "open";
980
+ closed: "closed";
981
+ merged: "merged";
982
+ }>;
983
+ draft: z.ZodMiniOptional<z.ZodMiniLiteral<true>>;
984
+ checks: z.ZodMiniOptional<z.ZodMiniEnum<{
985
+ pending: "pending";
986
+ success: "success";
987
+ failure: "failure";
988
+ }>>;
989
+ review: z.ZodMiniOptional<z.ZodMiniEnum<{
990
+ approved: "approved";
991
+ changes_requested: "changes_requested";
992
+ }>>;
993
+ preview_url: z.ZodMiniOptional<z.ZodMiniString<string>>;
994
+ preview_status: z.ZodMiniOptional<z.ZodMiniEnum<{
995
+ building: "building";
996
+ ready: "ready";
997
+ failed: "failed";
998
+ }>>;
999
+ linked_by: z.ZodMiniEnum<{
1000
+ auto: "auto";
1001
+ manual: "manual";
1002
+ }>;
1003
+ }, z.core.$strip>;
1004
+ declare const zUnlinkTaskPullRequestPath: z.ZodMiniObject<{
1005
+ id: z.ZodMiniString<string>;
1006
+ prId: z.ZodMiniUUID;
1007
+ }, z.core.$strip>;
1008
+ /**
1009
+ * Unlinked
1010
+ */
1011
+ declare const zUnlinkTaskPullRequestResponse: z.ZodMiniVoid;
741
1012
 
742
1013
  interface PerspecTaskOptions {
743
1014
  /**
744
1015
  * Your PerspecTask API key (begins with `pt_live_`). Create one in the web
745
- * app under **Settings → API**. Carries `tasks:read` / `tasks:write` scopes.
1016
+ * app under **Account → API Keys**. Carries `tasks:read` / `tasks:write` scopes.
1017
+ *
1018
+ * Or a function returning a token, called before every request: that's how
1019
+ * a `pt login` OAuth token is refreshed when it expires (see
1020
+ * `resolveCredential` in `@perspectask/sdk/credentials`).
746
1021
  */
747
- apiKey: string;
1022
+ apiKey: string | (() => string | Promise<string>);
748
1023
  /**
749
1024
  * Override the API base URL. Defaults to `https://api.perspectask.com/v1`.
750
1025
  * Mostly useful for staging or local development.
751
1026
  */
752
1027
  baseUrl?: string;
1028
+ /**
1029
+ * Override the `fetch` the client uses. The hosted MCP server passes one that
1030
+ * calls the API on its own host; most callers never need it.
1031
+ */
1032
+ fetch?: typeof fetch;
753
1033
  }
754
1034
  /**
755
1035
  * Official TypeScript SDK for the PerspecTask API.
@@ -821,6 +1101,46 @@ declare function createTasksNamespace(client: Client): {
821
1101
  request?: Request;
822
1102
  response?: Response;
823
1103
  }>;
1104
+ /**
1105
+ * GitHub pull requests linked to a task. Usually you don't need these: put
1106
+ * the task's `pr_token` (e.g. `pt-a3f91c2`, on `tasks.get`) in a PR title
1107
+ * or branch name and the PR links itself.
1108
+ */
1109
+ pullRequests: {
1110
+ /** List the task's linked PRs (state, checks, review, preview). Wraps `PullRequests.listTaskPullRequests`. */
1111
+ list: (id: string) => Promise<({
1112
+ data: PullRequest[];
1113
+ error: undefined;
1114
+ } | {
1115
+ data: undefined;
1116
+ error: unknown;
1117
+ }) & {
1118
+ request?: Request;
1119
+ response?: Response;
1120
+ }>;
1121
+ /** Link a PR by URL (`https://github.com/o/r/pull/12` or `o/r#12`). Wraps `PullRequests.linkTaskPullRequest`. */
1122
+ link: (id: string, url: string) => Promise<({
1123
+ data: PullRequest;
1124
+ error: undefined;
1125
+ } | {
1126
+ data: undefined;
1127
+ error: unknown;
1128
+ }) & {
1129
+ request?: Request;
1130
+ response?: Response;
1131
+ }>;
1132
+ /** Unlink by the link `id` from `list`. Wraps `PullRequests.unlinkTaskPullRequest`. */
1133
+ unlink: (id: string, prId: string) => Promise<({
1134
+ data: void;
1135
+ error: undefined;
1136
+ } | {
1137
+ data: undefined;
1138
+ error: unknown;
1139
+ }) & {
1140
+ request?: Request;
1141
+ response?: Response;
1142
+ }>;
1143
+ };
824
1144
  };
825
1145
 
826
- export { type ClientOptions, type CreateTaskData, type CreateTaskResponse, type CreateTaskResponses, type GetTaskData, type GetTaskErrors, type GetTaskResponse, type GetTaskResponses, type ListTasksData, type ListTasksResponse, type ListTasksResponses, type Options, PerspecTask, type PerspecTaskOptions, type Task, Tasks, type UpdateTaskData, type UpdateTaskErrors, type UpdateTaskResponse, type UpdateTaskResponses, PerspecTask as default, zCreateTaskBody, zCreateTaskResponse, zGetTaskPath, zGetTaskQuery, zGetTaskResponse, zListTasksQuery, zListTasksResponse, zTask, zUpdateTaskBody, zUpdateTaskPath, zUpdateTaskResponse };
1146
+ export { type ClientOptions, type CreateTaskData, type CreateTaskResponse, type CreateTaskResponses, type GetTaskData, type GetTaskErrors, type GetTaskResponse, type GetTaskResponses, type LinkTaskPullRequestData, type LinkTaskPullRequestErrors, type LinkTaskPullRequestResponse, type LinkTaskPullRequestResponses, type ListTaskPullRequestsData, type ListTaskPullRequestsErrors, type ListTaskPullRequestsResponse, type ListTaskPullRequestsResponses, type ListTasksData, type ListTasksResponse, type ListTasksResponses, type Options, PerspecTask, type PerspecTaskOptions, type PullRequest, PullRequests, type Task, Tasks, type UnlinkTaskPullRequestData, type UnlinkTaskPullRequestErrors, type UnlinkTaskPullRequestResponse, type UnlinkTaskPullRequestResponses, type UpdateTaskData, type UpdateTaskErrors, type UpdateTaskResponse, type UpdateTaskResponses, PerspecTask as default, zCreateTaskBody, zCreateTaskResponse, zGetTaskPath, zGetTaskQuery, zGetTaskResponse, zLinkTaskPullRequestBody, zLinkTaskPullRequestPath, zLinkTaskPullRequestResponse, zListTaskPullRequestsPath, zListTaskPullRequestsResponse, zListTasksQuery, zListTasksResponse, zPullRequest, zTask, zUnlinkTaskPullRequestPath, zUnlinkTaskPullRequestResponse, zUpdateTaskBody, zUpdateTaskPath, zUpdateTaskResponse };
package/dist/index.js CHANGED
@@ -1,3 +1,13 @@
1
+ import {
2
+ CLI_CLIENT_ID,
3
+ DEFAULT_BASE_URL,
4
+ OAuthTokenError,
5
+ refreshTokens,
6
+ revokeTokens,
7
+ startDeviceLogin,
8
+ waitForDeviceLogin
9
+ } from "./chunk-56FPFSE2.js";
10
+
1
11
  // src/generated/core/bodySerializer.gen.ts
2
12
  var jsonBodySerializer = {
3
13
  bodySerializer: (body) => JSON.stringify(body, (_key, value) => typeof value === "bigint" ? value.toString() : value)
@@ -837,6 +847,48 @@ var Tasks = class {
837
847
  });
838
848
  }
839
849
  };
850
+ var PullRequests = class {
851
+ /**
852
+ * List pull requests linked to a task
853
+ *
854
+ * 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).
855
+ */
856
+ static listTaskPullRequests(options) {
857
+ return (options.client ?? client).get({
858
+ security: [{ scheme: "bearer", type: "http" }],
859
+ url: "/tasks/{id}/pull-requests",
860
+ ...options
861
+ });
862
+ }
863
+ /**
864
+ * Link a pull request to a task
865
+ *
866
+ * 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.
867
+ */
868
+ static linkTaskPullRequest(options) {
869
+ return (options.client ?? client).post({
870
+ security: [{ scheme: "bearer", type: "http" }],
871
+ url: "/tasks/{id}/pull-requests",
872
+ ...options,
873
+ headers: {
874
+ "Content-Type": "application/json",
875
+ ...options.headers
876
+ }
877
+ });
878
+ }
879
+ /**
880
+ * Unlink a pull request from a task
881
+ *
882
+ * 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.
883
+ */
884
+ static unlinkTaskPullRequest(options) {
885
+ return (options.client ?? client).delete({
886
+ security: [{ scheme: "bearer", type: "http" }],
887
+ url: "/tasks/{id}/pull-requests/{prId}",
888
+ ...options
889
+ });
890
+ }
891
+ };
840
892
 
841
893
  // src/generated/zod.gen.ts
842
894
  import * as z from "zod/mini";
@@ -844,6 +896,9 @@ var zTask = z.object({
844
896
  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, {
845
897
  description: 'Short id: the minimum unique prefix of the task UUID (e.g. "a3f"). Accepted anywhere an id is.'
846
898
  })),
899
+ pr_token: z.optional(z.string().check(z.regex(/^pt-[0-9a-f]{7,32}$/)).register(z.globalRegistry, {
900
+ 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.'
901
+ })),
847
902
  title: z.optional(z.string()),
848
903
  description: z.optional(z.string()),
849
904
  encrypted: z.optional(z.boolean().register(z.globalRegistry, {
@@ -884,6 +939,48 @@ var zTask = z.object({
884
939
  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)]))),
885
940
  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}$/))))
886
941
  });
942
+ var zPullRequest = z.object({
943
+ id: z.uuid().register(z.globalRegistry, {
944
+ description: "Id of this task\u2194PR link. Pass it to unlink."
945
+ }),
946
+ repo: z.string(),
947
+ number: z.int(),
948
+ title: z.string(),
949
+ url: z.string().register(z.globalRegistry, {
950
+ description: "The PR on github.com."
951
+ }),
952
+ state: z.enum([
953
+ "open",
954
+ "closed",
955
+ "merged"
956
+ ]),
957
+ draft: z.optional(z.literal(true).register(z.globalRegistry, {
958
+ description: "Only present when the PR is a draft."
959
+ })),
960
+ checks: z.optional(z.enum([
961
+ "pending",
962
+ "success",
963
+ "failure"
964
+ ]).register(z.globalRegistry, {
965
+ description: "Combined CI result of the PR's head commit (check runs + commit statuses). Omitted when the commit has no CI."
966
+ })),
967
+ review: z.optional(z.enum(["approved", "changes_requested"]).register(z.globalRegistry, {
968
+ description: "Reviewers' current decision. Omitted when nobody approved or requested changes."
969
+ })),
970
+ preview_url: z.optional(z.string().register(z.globalRegistry, {
971
+ description: "Latest successful preview deployment (Vercel, Netlify, \u2026). Omitted when there is none."
972
+ })),
973
+ preview_status: z.optional(z.enum([
974
+ "building",
975
+ "ready",
976
+ "failed"
977
+ ]).register(z.globalRegistry, {
978
+ description: "State of the preview deploy of the PR's head commit: `building` while it deploys, `ready` when it's live, `failed` when it broke. `preview_url` stays the last successful preview meanwhile. Omitted when no deploy was seen for that commit."
979
+ })),
980
+ linked_by: z.enum(["auto", "manual"]).register(z.globalRegistry, {
981
+ description: "`auto` = linked by the pt- code in the PR; `manual` = linked by URL."
982
+ })
983
+ });
887
984
  var zListTasksQuery = z.object({
888
985
  includeEncrypted: z.optional(z.boolean().register(z.globalRegistry, {
889
986
  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."
@@ -992,6 +1089,30 @@ var zUpdateTaskPath = z.object({
992
1089
  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}$/))
993
1090
  });
994
1091
  var zUpdateTaskResponse = zTask;
1092
+ var zListTaskPullRequestsPath = z.object({
1093
+ 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}$/))
1094
+ });
1095
+ var zListTaskPullRequestsResponse = z.array(zPullRequest).register(z.globalRegistry, {
1096
+ description: "Linked pull requests (oldest first)"
1097
+ });
1098
+ var zLinkTaskPullRequestBody = z.object({
1099
+ url: z.string().check(z.minLength(1)).register(z.globalRegistry, {
1100
+ description: "The pull request: `https://github.com/owner/repo/pull/123` or `owner/repo#123`."
1101
+ })
1102
+ });
1103
+ var zLinkTaskPullRequestPath = z.object({
1104
+ 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}$/))
1105
+ });
1106
+ var zLinkTaskPullRequestResponse = zPullRequest;
1107
+ var zUnlinkTaskPullRequestPath = z.object({
1108
+ 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}$/)),
1109
+ prId: z.uuid().register(z.globalRegistry, {
1110
+ description: "The link id (`id` from the pull request list)."
1111
+ })
1112
+ });
1113
+ var zUnlinkTaskPullRequestResponse = z.void().register(z.globalRegistry, {
1114
+ description: "Unlinked"
1115
+ });
995
1116
 
996
1117
  // src/index.ts
997
1118
  var PerspecTask = class {
@@ -1001,14 +1122,20 @@ var PerspecTask = class {
1001
1122
  */
1002
1123
  tasks;
1003
1124
  constructor(options) {
1125
+ const { apiKey } = options;
1004
1126
  const client2 = createClient(
1005
1127
  createConfig({
1006
- baseUrl: options.baseUrl ?? "https://api.perspectask.com/v1",
1007
- headers: {
1008
- Authorization: `Bearer ${options.apiKey}`
1009
- }
1128
+ baseUrl: options.baseUrl ?? DEFAULT_BASE_URL,
1129
+ ...options.fetch ? { fetch: options.fetch } : {},
1130
+ ...typeof apiKey === "string" ? { headers: { Authorization: `Bearer ${apiKey}` } } : {}
1010
1131
  })
1011
1132
  );
1133
+ if (typeof apiKey === "function") {
1134
+ client2.interceptors.request.use(async (request) => {
1135
+ request.headers.set("Authorization", `Bearer ${await apiKey()}`);
1136
+ return request;
1137
+ });
1138
+ }
1012
1139
  this.tasks = createTasksNamespace(client2);
1013
1140
  }
1014
1141
  };
@@ -1021,22 +1148,51 @@ function createTasksNamespace(client2) {
1021
1148
  /** Create a task (`title` required). Wraps `Tasks.createTask`. */
1022
1149
  create: (body) => Tasks.createTask({ client: client2, body }),
1023
1150
  /** Update editable fields on a task by id. Wraps `Tasks.updateTask`. */
1024
- update: (id, body) => Tasks.updateTask({ client: client2, path: { id }, body })
1151
+ update: (id, body) => Tasks.updateTask({ client: client2, path: { id }, body }),
1152
+ /**
1153
+ * GitHub pull requests linked to a task. Usually you don't need these: put
1154
+ * the task's `pr_token` (e.g. `pt-a3f91c2`, on `tasks.get`) in a PR title
1155
+ * or branch name and the PR links itself.
1156
+ */
1157
+ pullRequests: {
1158
+ /** List the task's linked PRs (state, checks, review, preview). Wraps `PullRequests.listTaskPullRequests`. */
1159
+ list: (id) => PullRequests.listTaskPullRequests({ client: client2, path: { id } }),
1160
+ /** Link a PR by URL (`https://github.com/o/r/pull/12` or `o/r#12`). Wraps `PullRequests.linkTaskPullRequest`. */
1161
+ link: (id, url) => PullRequests.linkTaskPullRequest({ client: client2, path: { id }, body: { url } }),
1162
+ /** Unlink by the link `id` from `list`. Wraps `PullRequests.unlinkTaskPullRequest`. */
1163
+ unlink: (id, prId) => PullRequests.unlinkTaskPullRequest({ client: client2, path: { id, prId } })
1164
+ }
1025
1165
  };
1026
1166
  }
1027
1167
  var index_default = PerspecTask;
1028
1168
  export {
1169
+ CLI_CLIENT_ID,
1170
+ DEFAULT_BASE_URL,
1171
+ OAuthTokenError,
1029
1172
  PerspecTask,
1173
+ PullRequests,
1030
1174
  Tasks,
1031
1175
  index_default as default,
1176
+ refreshTokens,
1177
+ revokeTokens,
1178
+ startDeviceLogin,
1179
+ waitForDeviceLogin,
1032
1180
  zCreateTaskBody,
1033
1181
  zCreateTaskResponse,
1034
1182
  zGetTaskPath,
1035
1183
  zGetTaskQuery,
1036
1184
  zGetTaskResponse,
1185
+ zLinkTaskPullRequestBody,
1186
+ zLinkTaskPullRequestPath,
1187
+ zLinkTaskPullRequestResponse,
1188
+ zListTaskPullRequestsPath,
1189
+ zListTaskPullRequestsResponse,
1037
1190
  zListTasksQuery,
1038
1191
  zListTasksResponse,
1192
+ zPullRequest,
1039
1193
  zTask,
1194
+ zUnlinkTaskPullRequestPath,
1195
+ zUnlinkTaskPullRequestResponse,
1040
1196
  zUpdateTaskBody,
1041
1197
  zUpdateTaskPath,
1042
1198
  zUpdateTaskResponse