@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.cts 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.cjs';
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 };