@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/dist/index.d.cts CHANGED
@@ -400,6 +400,28 @@ type PullRequest = {
400
400
  */
401
401
  linked_by: 'auto' | 'manual';
402
402
  };
403
+ type KpiEntry = {
404
+ /**
405
+ * Id of this entry. Pass it to update or delete.
406
+ */
407
+ id: string;
408
+ /**
409
+ * `target` = the number you aim for (by `at`); `actual` = a reading of where it stands at `at`.
410
+ */
411
+ kind: 'target' | 'actual';
412
+ /**
413
+ * ISO 8601 UTC instant. Omitted for a target with no date.
414
+ */
415
+ at?: string;
416
+ /**
417
+ * The number. Omitted when the entry was saved end-to-end encrypted (then `encrypted` is true).
418
+ */
419
+ value?: number;
420
+ /**
421
+ * Only present when the value is end-to-end encrypted and so not readable over the API.
422
+ */
423
+ encrypted?: true;
424
+ };
403
425
  type ListTasksData = {
404
426
  body?: never;
405
427
  path?: never;
@@ -650,6 +672,149 @@ type UnlinkTaskPullRequestResponses = {
650
672
  204: void;
651
673
  };
652
674
  type UnlinkTaskPullRequestResponse = UnlinkTaskPullRequestResponses[keyof UnlinkTaskPullRequestResponses];
675
+ type ListKpiTasksData = {
676
+ body?: never;
677
+ path?: never;
678
+ query?: never;
679
+ url: '/kpis';
680
+ };
681
+ type ListKpiTasksResponses = {
682
+ /**
683
+ * Short ids of the tasks that have KPI entries.
684
+ */
685
+ 200: Array<string>;
686
+ };
687
+ type ListKpiTasksResponse = ListKpiTasksResponses[keyof ListKpiTasksResponses];
688
+ type ListTaskKpisData = {
689
+ body?: never;
690
+ path: {
691
+ id: string;
692
+ };
693
+ query?: never;
694
+ url: '/tasks/{id}/kpis';
695
+ };
696
+ type ListTaskKpisErrors = {
697
+ /**
698
+ * Task is encrypted
699
+ */
700
+ 403: unknown;
701
+ /**
702
+ * Task not found
703
+ */
704
+ 404: unknown;
705
+ };
706
+ type ListTaskKpisResponses = {
707
+ /**
708
+ * KPI entries
709
+ */
710
+ 200: Array<KpiEntry>;
711
+ };
712
+ type ListTaskKpisResponse = ListTaskKpisResponses[keyof ListTaskKpisResponses];
713
+ type CreateTaskKpiData = {
714
+ body: {
715
+ kind: 'target' | 'actual';
716
+ value: number;
717
+ /**
718
+ * When the target is due, or when the actual was measured. Required for an actual; a target may have none.
719
+ */
720
+ at?: string;
721
+ };
722
+ path: {
723
+ id: string;
724
+ };
725
+ query?: never;
726
+ url: '/tasks/{id}/kpis';
727
+ };
728
+ type CreateTaskKpiErrors = {
729
+ /**
730
+ * Invalid entry (e.g. an actual without `at`)
731
+ */
732
+ 400: unknown;
733
+ /**
734
+ * Task is encrypted
735
+ */
736
+ 403: unknown;
737
+ /**
738
+ * Task not found
739
+ */
740
+ 404: unknown;
741
+ };
742
+ type CreateTaskKpiResponses = {
743
+ /**
744
+ * Created
745
+ */
746
+ 201: KpiEntry;
747
+ };
748
+ type CreateTaskKpiResponse = CreateTaskKpiResponses[keyof CreateTaskKpiResponses];
749
+ type DeleteTaskKpiData = {
750
+ body?: never;
751
+ path: {
752
+ id: string;
753
+ /**
754
+ * The entry id (`id` from the KPI list).
755
+ */
756
+ kpiId: string;
757
+ };
758
+ query?: never;
759
+ url: '/tasks/{id}/kpis/{kpiId}';
760
+ };
761
+ type DeleteTaskKpiErrors = {
762
+ /**
763
+ * Task is encrypted
764
+ */
765
+ 403: unknown;
766
+ /**
767
+ * Task or entry not found
768
+ */
769
+ 404: unknown;
770
+ };
771
+ type DeleteTaskKpiResponses = {
772
+ /**
773
+ * Deleted
774
+ */
775
+ 204: void;
776
+ };
777
+ type DeleteTaskKpiResponse = DeleteTaskKpiResponses[keyof DeleteTaskKpiResponses];
778
+ type UpdateTaskKpiData = {
779
+ body: {
780
+ kind?: 'target' | 'actual';
781
+ value?: number;
782
+ /**
783
+ * `null` removes the date (a target only).
784
+ */
785
+ at?: string | null;
786
+ };
787
+ path: {
788
+ id: string;
789
+ /**
790
+ * The entry id (`id` from the KPI list).
791
+ */
792
+ kpiId: string;
793
+ };
794
+ query?: never;
795
+ url: '/tasks/{id}/kpis/{kpiId}';
796
+ };
797
+ type UpdateTaskKpiErrors = {
798
+ /**
799
+ * Nothing to update, or an actual left without `at`
800
+ */
801
+ 400: unknown;
802
+ /**
803
+ * Task is encrypted
804
+ */
805
+ 403: unknown;
806
+ /**
807
+ * Task or entry not found
808
+ */
809
+ 404: unknown;
810
+ };
811
+ type UpdateTaskKpiResponses = {
812
+ /**
813
+ * Updated
814
+ */
815
+ 200: KpiEntry;
816
+ };
817
+ type UpdateTaskKpiResponse = UpdateTaskKpiResponses[keyof UpdateTaskKpiResponses];
653
818
 
654
819
  type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean, TResponse = unknown> = Options$1<TData, ThrowOnError, TResponse> & {
655
820
  /**
@@ -702,6 +867,36 @@ declare class PullRequests {
702
867
  */
703
868
  static unlinkTaskPullRequest<ThrowOnError extends boolean = false>(options: Options<UnlinkTaskPullRequestData, ThrowOnError>): RequestResult<UnlinkTaskPullRequestResponses, UnlinkTaskPullRequestErrors, ThrowOnError, "fields">;
704
869
  }
870
+ declare class Kpis {
871
+ /**
872
+ * List tasks with KPIs
873
+ *
874
+ * Short ids of your tasks that have KPI entries. Encrypted tasks are left out. Fetch a task with `GET /tasks/{id}` for its title.
875
+ */
876
+ static listKpiTasks<ThrowOnError extends boolean = false>(options?: Options<ListKpiTasksData, ThrowOnError>): RequestResult<ListKpiTasksResponses, unknown, ThrowOnError, "fields">;
877
+ /**
878
+ * List the KPI entries of a task
879
+ *
880
+ * 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`.
881
+ */
882
+ static listTaskKpis<ThrowOnError extends boolean = false>(options: Options<ListTaskKpisData, ThrowOnError>): RequestResult<ListTaskKpisResponses, ListTaskKpisErrors, ThrowOnError, "fields">;
883
+ /**
884
+ * Add a KPI entry to a task
885
+ *
886
+ * 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`.
887
+ */
888
+ static createTaskKpi<ThrowOnError extends boolean = false>(options: Options<CreateTaskKpiData, ThrowOnError>): RequestResult<CreateTaskKpiResponses, CreateTaskKpiErrors, ThrowOnError, "fields">;
889
+ /**
890
+ * Delete a KPI entry
891
+ */
892
+ static deleteTaskKpi<ThrowOnError extends boolean = false>(options: Options<DeleteTaskKpiData, ThrowOnError>): RequestResult<DeleteTaskKpiResponses, DeleteTaskKpiErrors, ThrowOnError, "fields">;
893
+ /**
894
+ * Update a KPI entry
895
+ *
896
+ * Change any of `kind`, `value` and `at`. Only the fields you send change.
897
+ */
898
+ static updateTaskKpi<ThrowOnError extends boolean = false>(options: Options<UpdateTaskKpiData, ThrowOnError>): RequestResult<UpdateTaskKpiResponses, UpdateTaskKpiErrors, ThrowOnError, "fields">;
899
+ }
705
900
 
706
901
  declare const zTask: z.ZodMiniObject<{
707
902
  id: z.ZodMiniOptional<z.ZodMiniString<string>>;
@@ -760,6 +955,16 @@ declare const zPullRequest: z.ZodMiniObject<{
760
955
  manual: "manual";
761
956
  }>;
762
957
  }, z.core.$strip>;
958
+ declare const zKpiEntry: z.ZodMiniObject<{
959
+ id: z.ZodMiniUUID;
960
+ kind: z.ZodMiniEnum<{
961
+ target: "target";
962
+ actual: "actual";
963
+ }>;
964
+ at: z.ZodMiniOptional<z.ZodMiniString<string>>;
965
+ value: z.ZodMiniOptional<z.ZodMiniNumber<number>>;
966
+ encrypted: z.ZodMiniOptional<z.ZodMiniLiteral<true>>;
967
+ }, z.core.$strip>;
763
968
  declare const zListTasksQuery: z.ZodMiniObject<{
764
969
  includeEncrypted: z.ZodMiniOptional<z.ZodMiniBoolean<boolean>>;
765
970
  tree: z.ZodMiniOptional<z.ZodMiniBoolean<boolean>>;
@@ -1009,11 +1214,89 @@ declare const zUnlinkTaskPullRequestPath: z.ZodMiniObject<{
1009
1214
  * Unlinked
1010
1215
  */
1011
1216
  declare const zUnlinkTaskPullRequestResponse: z.ZodMiniVoid;
1217
+ /**
1218
+ * Short ids of the tasks that have KPI entries.
1219
+ */
1220
+ declare const zListKpiTasksResponse: z.ZodMiniArray<z.ZodMiniString<string>>;
1221
+ declare const zListTaskKpisPath: z.ZodMiniObject<{
1222
+ id: z.ZodMiniString<string>;
1223
+ }, z.core.$strip>;
1224
+ /**
1225
+ * KPI entries
1226
+ */
1227
+ declare const zListTaskKpisResponse: z.ZodMiniArray<z.ZodMiniObject<{
1228
+ id: z.ZodMiniUUID;
1229
+ kind: z.ZodMiniEnum<{
1230
+ target: "target";
1231
+ actual: "actual";
1232
+ }>;
1233
+ at: z.ZodMiniOptional<z.ZodMiniString<string>>;
1234
+ value: z.ZodMiniOptional<z.ZodMiniNumber<number>>;
1235
+ encrypted: z.ZodMiniOptional<z.ZodMiniLiteral<true>>;
1236
+ }, z.core.$strip>>;
1237
+ declare const zCreateTaskKpiBody: z.ZodMiniObject<{
1238
+ kind: z.ZodMiniEnum<{
1239
+ target: "target";
1240
+ actual: "actual";
1241
+ }>;
1242
+ value: z.ZodMiniNumber<number>;
1243
+ at: z.ZodMiniOptional<z.iso.ZodMiniISODateTime>;
1244
+ }, z.core.$strip>;
1245
+ declare const zCreateTaskKpiPath: z.ZodMiniObject<{
1246
+ id: z.ZodMiniString<string>;
1247
+ }, z.core.$strip>;
1248
+ /**
1249
+ * Created
1250
+ */
1251
+ declare const zCreateTaskKpiResponse: z.ZodMiniObject<{
1252
+ id: z.ZodMiniUUID;
1253
+ kind: z.ZodMiniEnum<{
1254
+ target: "target";
1255
+ actual: "actual";
1256
+ }>;
1257
+ at: z.ZodMiniOptional<z.ZodMiniString<string>>;
1258
+ value: z.ZodMiniOptional<z.ZodMiniNumber<number>>;
1259
+ encrypted: z.ZodMiniOptional<z.ZodMiniLiteral<true>>;
1260
+ }, z.core.$strip>;
1261
+ declare const zDeleteTaskKpiPath: z.ZodMiniObject<{
1262
+ id: z.ZodMiniString<string>;
1263
+ kpiId: z.ZodMiniUUID;
1264
+ }, z.core.$strip>;
1265
+ /**
1266
+ * Deleted
1267
+ */
1268
+ declare const zDeleteTaskKpiResponse: z.ZodMiniVoid;
1269
+ declare const zUpdateTaskKpiBody: z.ZodMiniObject<{
1270
+ kind: z.ZodMiniOptional<z.ZodMiniEnum<{
1271
+ target: "target";
1272
+ actual: "actual";
1273
+ }>>;
1274
+ value: z.ZodMiniOptional<z.ZodMiniNumber<number>>;
1275
+ at: z.ZodMiniOptional<z.ZodMiniNullable<z.iso.ZodMiniISODateTime>>;
1276
+ }, z.core.$strip>;
1277
+ declare const zUpdateTaskKpiPath: z.ZodMiniObject<{
1278
+ id: z.ZodMiniString<string>;
1279
+ kpiId: z.ZodMiniUUID;
1280
+ }, z.core.$strip>;
1281
+ /**
1282
+ * Updated
1283
+ */
1284
+ declare const zUpdateTaskKpiResponse: z.ZodMiniObject<{
1285
+ id: z.ZodMiniUUID;
1286
+ kind: z.ZodMiniEnum<{
1287
+ target: "target";
1288
+ actual: "actual";
1289
+ }>;
1290
+ at: z.ZodMiniOptional<z.ZodMiniString<string>>;
1291
+ value: z.ZodMiniOptional<z.ZodMiniNumber<number>>;
1292
+ encrypted: z.ZodMiniOptional<z.ZodMiniLiteral<true>>;
1293
+ }, z.core.$strip>;
1012
1294
 
1013
1295
  interface PerspecTaskOptions {
1014
1296
  /**
1015
1297
  * Your PerspecTask API key (begins with `pt_live_`). Create one in the web
1016
- * app under **Account → API Keys**. Carries `tasks:read` / `tasks:write` scopes.
1298
+ * app under **Account → API Keys**. Carries `tasks:read` / `tasks:write`
1299
+ * scopes, and `kpis:read` / `kpis:write` for KPIs.
1017
1300
  *
1018
1301
  * Or a function returning a token, called before every request: that's how
1019
1302
  * a `pt login` OAuth token is refreshed when it expires (see
@@ -1141,6 +1424,68 @@ declare function createTasksNamespace(client: Client): {
1141
1424
  response?: Response;
1142
1425
  }>;
1143
1426
  };
1427
+ /**
1428
+ * A task's KPI: `target` entries (the number to reach, optionally by a
1429
+ * date) and `actual` entries (readings over time). Needs the `kpis:read` /
1430
+ * `kpis:write` scopes.
1431
+ */
1432
+ kpis: {
1433
+ /** Short ids of the tasks that have KPI entries. Wraps `Kpis.listKpiTasks`. */
1434
+ listTasks: () => Promise<({
1435
+ data: undefined;
1436
+ error: unknown;
1437
+ } | {
1438
+ data: string[];
1439
+ error: undefined;
1440
+ }) & {
1441
+ request?: Request;
1442
+ response?: Response;
1443
+ }>;
1444
+ /** The task's entries, oldest first. Wraps `Kpis.listTaskKpis`. */
1445
+ list: (id: string) => Promise<({
1446
+ data: KpiEntry[];
1447
+ error: undefined;
1448
+ } | {
1449
+ data: undefined;
1450
+ error: unknown;
1451
+ }) & {
1452
+ request?: Request;
1453
+ response?: Response;
1454
+ }>;
1455
+ /** Add a target or an actual (`at` required for an actual). Wraps `Kpis.createTaskKpi`. */
1456
+ create: (id: string, body: CreateTaskKpiData["body"]) => Promise<({
1457
+ data: KpiEntry;
1458
+ error: undefined;
1459
+ } | {
1460
+ data: undefined;
1461
+ error: unknown;
1462
+ }) & {
1463
+ request?: Request;
1464
+ response?: Response;
1465
+ }>;
1466
+ /** Change an entry's kind, value or at (`at: null` drops a target's date). Wraps `Kpis.updateTaskKpi`. */
1467
+ update: (id: string, kpiId: string, body: UpdateTaskKpiData["body"]) => Promise<({
1468
+ data: KpiEntry;
1469
+ error: undefined;
1470
+ } | {
1471
+ data: undefined;
1472
+ error: unknown;
1473
+ }) & {
1474
+ request?: Request;
1475
+ response?: Response;
1476
+ }>;
1477
+ /** Delete an entry by its `id` from `list`. Wraps `Kpis.deleteTaskKpi`. */
1478
+ delete: (id: string, kpiId: string) => Promise<({
1479
+ data: void;
1480
+ error: undefined;
1481
+ } | {
1482
+ data: undefined;
1483
+ error: unknown;
1484
+ }) & {
1485
+ request?: Request;
1486
+ response?: Response;
1487
+ }>;
1488
+ };
1144
1489
  };
1145
1490
 
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 };
1491
+ export { type ClientOptions, type CreateTaskData, type CreateTaskKpiData, type CreateTaskKpiErrors, type CreateTaskKpiResponse, type CreateTaskKpiResponses, type CreateTaskResponse, type CreateTaskResponses, type DeleteTaskKpiData, type DeleteTaskKpiErrors, type DeleteTaskKpiResponse, type DeleteTaskKpiResponses, type GetTaskData, type GetTaskErrors, type GetTaskResponse, type GetTaskResponses, type KpiEntry, Kpis, type LinkTaskPullRequestData, type LinkTaskPullRequestErrors, type LinkTaskPullRequestResponse, type LinkTaskPullRequestResponses, type ListKpiTasksData, type ListKpiTasksResponse, type ListKpiTasksResponses, type ListTaskKpisData, type ListTaskKpisErrors, type ListTaskKpisResponse, type ListTaskKpisResponses, 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 UpdateTaskKpiData, type UpdateTaskKpiErrors, type UpdateTaskKpiResponse, type UpdateTaskKpiResponses, type UpdateTaskResponse, type UpdateTaskResponses, PerspecTask as default, zCreateTaskBody, zCreateTaskKpiBody, zCreateTaskKpiPath, zCreateTaskKpiResponse, zCreateTaskResponse, zDeleteTaskKpiPath, zDeleteTaskKpiResponse, zGetTaskPath, zGetTaskQuery, zGetTaskResponse, zKpiEntry, zLinkTaskPullRequestBody, zLinkTaskPullRequestPath, zLinkTaskPullRequestResponse, zListKpiTasksResponse, zListTaskKpisPath, zListTaskKpisResponse, zListTaskPullRequestsPath, zListTaskPullRequestsResponse, zListTasksQuery, zListTasksResponse, zPullRequest, zTask, zUnlinkTaskPullRequestPath, zUnlinkTaskPullRequestResponse, zUpdateTaskBody, zUpdateTaskKpiBody, zUpdateTaskKpiPath, zUpdateTaskKpiResponse, zUpdateTaskPath, zUpdateTaskResponse };