@devpad/api 2.3.4 → 2.3.5

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.
@@ -52,6 +52,11 @@ var api_keys = sqliteTable("api_keys", {
52
52
  name: text("name"),
53
53
  note: text("note"),
54
54
  scope: text("scope", { enum: ["devpad", "blog", "media", "pulse", "all"] }).notNull().default("all"),
55
+ // v2.4 (task A3.1): nullable project scope. `null` = legacy all-projects
56
+ // key, behaves exactly as before. Non-null keys are rejected by the
57
+ // scope guard (`packages/worker/src/middleware/scope-guard.ts`) on any
58
+ // resource belonging to a different project.
59
+ project_id: text("project_id").references(() => project.id),
55
60
  enabled: integer("enabled", { mode: "boolean" }).notNull().default(true),
56
61
  last_used_at: text("last_used_at"),
57
62
  ...timestamps(),
@@ -71,7 +76,11 @@ var project = sqliteTable("project", {
71
76
  link_text: text("link_text"),
72
77
  visibility: text("visibility", { enum: ["PUBLIC", "PRIVATE", "HIDDEN", "ARCHIVED", "DRAFT", "DELETED"] }).notNull().default("PRIVATE"),
73
78
  current_version: text("current_version"),
74
- scan_branch: text("scan_branch")
79
+ scan_branch: text("scan_branch"),
80
+ // v2.4 (task A3.6) — per-project opt-in, OFF by default: a merged PR
81
+ // completes its linked task automatically via the GitHub App inbound
82
+ // webhook. Diff-linked status because agents are unreliable narrators.
83
+ github_autoclose: integer("github_autoclose", { mode: "boolean" }).notNull().default(false)
75
84
  });
76
85
  var ACTIONS = [
77
86
  "CREATE_TASK",
@@ -227,6 +236,36 @@ var task_event = sqliteTable("task_event", {
227
236
  index("task_event_subject_id_idx").on(table.subject_id),
228
237
  index("task_event_dispatch_status_idx").on(table.dispatch_status)
229
238
  ]);
239
+ var hook = sqliteTable("hook", {
240
+ ...entity("hook"),
241
+ project_id: text("project_id").notNull().references(() => project.id),
242
+ enabled: integer("enabled", { mode: "boolean" }).notNull().default(true),
243
+ // HookTrigger: { kinds: TaskEventKind[], selector: { subject_kind?, tag?, ancestor_id? } }
244
+ trigger: text("trigger", { mode: "json" }).notNull(),
245
+ // HookAction: { kind: "webhook", url, secret_encrypted? } | { kind: "vault", scope, op, args? } | { kind: "pipeline", package_id }
246
+ action: text("action", { mode: "json" }).notNull()
247
+ }, (table) => [index("hook_project_id_idx").on(table.project_id)]);
248
+ var HOOK_DELIVERY_STATUSES = ["pending", "delivered", "failed_transient", "failed_permanent"];
249
+ var hook_delivery = sqliteTable("hook_delivery", {
250
+ // PK = sha256(`${event_id}:${hook_id}`) — see hooks/dispatch.ts's
251
+ // `hook_delivery_id`. Never generated any other way.
252
+ id: text("id").primaryKey(),
253
+ hook_id: text("hook_id").notNull().references(() => hook.id),
254
+ event_id: text("event_id").notNull(),
255
+ status: text("status", { enum: HOOK_DELIVERY_STATUSES }).notNull().default("pending"),
256
+ attempts: integer("attempts").notNull().default(0),
257
+ last_error: text("last_error"),
258
+ ...timestamps()
259
+ }, (table) => [
260
+ index("hook_delivery_hook_id_idx").on(table.hook_id),
261
+ index("hook_delivery_status_idx").on(table.status)
262
+ ]);
263
+ var github_webhook_event = sqliteTable("github_webhook_event", {
264
+ id: text("id").primaryKey(),
265
+ delivery_guid: text("delivery_guid").notNull(),
266
+ event_type: text("event_type").notNull(),
267
+ processed_at: text("processed_at").notNull().default(sql`(CURRENT_TIMESTAMP)`)
268
+ }, (table) => [index("github_webhook_event_delivery_guid_idx").on(table.delivery_guid)]);
230
269
  var checklist = sqliteTable("checklist", {
231
270
  ...entity("checklist"),
232
271
  task_id: text("task_id").notNull().references(() => task.id),
@@ -425,6 +464,13 @@ var task_rollup_relations = relations(task_rollup, ({ one }) => ({
425
464
  var task_event_relations = relations(task_event, ({ one }) => ({
426
465
  subject: one(task, { fields: [task_event.subject_id], references: [task.id] })
427
466
  }));
467
+ var hook_relations = relations(hook, ({ one, many }) => ({
468
+ project: one(project, { fields: [hook.project_id], references: [project.id] }),
469
+ deliveries: many(hook_delivery)
470
+ }));
471
+ var hook_delivery_relations = relations(hook_delivery, ({ one }) => ({
472
+ hook: one(hook, { fields: [hook_delivery.hook_id], references: [hook.id] })
473
+ }));
428
474
  var checklist_relations = relations(checklist, ({ one, many }) => ({
429
475
  task: one(task, { fields: [checklist.task_id], references: [task.id] }),
430
476
  items: many(checklist_item)
@@ -805,6 +851,52 @@ var task_event_payload = z.discriminatedUnion("kind", [
805
851
  z.object({ kind: z.literal("policy.fired"), policy: z.enum(COMPLETION_POLICIES) }),
806
852
  z.object({ kind: z.literal("node.completion_stale"), child_id: z.string() })
807
853
  ]);
854
+ var hook_selector = z.object({
855
+ subject_kind: z.enum(TASK_KINDS).optional(),
856
+ tag: z.string().optional(),
857
+ ancestor_id: z.string().optional()
858
+ });
859
+ var hook_trigger = z.object({
860
+ kinds: z.array(z.enum(TASK_EVENT_KINDS)).min(1),
861
+ selector: hook_selector.default({})
862
+ });
863
+ var hook_action_input = z.discriminatedUnion("kind", [
864
+ z.object({ kind: z.literal("webhook"), url: z.string().url(), secret: z.string().min(1).optional() }),
865
+ z.object({
866
+ kind: z.literal("vault"),
867
+ scope: z.string().min(1),
868
+ op: z.string().min(1),
869
+ args: z.record(z.string(), z.unknown()).optional()
870
+ }),
871
+ z.object({ kind: z.literal("pipeline"), package_id: z.string().min(1) })
872
+ ]);
873
+ var hook_action_stored = z.discriminatedUnion("kind", [
874
+ z.object({ kind: z.literal("webhook"), url: z.string().url(), secret_encrypted: z.string().optional() }),
875
+ z.object({
876
+ kind: z.literal("vault"),
877
+ scope: z.string().min(1),
878
+ op: z.string().min(1),
879
+ args: z.record(z.string(), z.unknown()).optional()
880
+ }),
881
+ z.object({ kind: z.literal("pipeline"), package_id: z.string().min(1) })
882
+ ]);
883
+ var hook_action_public = z.discriminatedUnion("kind", [
884
+ z.object({ kind: z.literal("webhook"), url: z.string().url(), has_secret: z.boolean() }),
885
+ z.object({
886
+ kind: z.literal("vault"),
887
+ scope: z.string().min(1),
888
+ op: z.string().min(1),
889
+ args: z.record(z.string(), z.unknown()).optional()
890
+ }),
891
+ z.object({ kind: z.literal("pipeline"), package_id: z.string().min(1) })
892
+ ]);
893
+ var upsert_hook = z.object({
894
+ id: z.string().optional(),
895
+ project_id: z.string(),
896
+ enabled: z.boolean().default(true),
897
+ trigger: hook_trigger,
898
+ action: hook_action_input
899
+ });
808
900
 
809
901
  export {
810
902
  GRAPH_DEPTH_CAP,
@@ -852,5 +944,11 @@ export {
852
944
  claim_request,
853
945
  done_request,
854
946
  task_event_actor,
855
- task_event_payload
947
+ task_event_payload,
948
+ hook_selector,
949
+ hook_trigger,
950
+ hook_action_input,
951
+ hook_action_stored,
952
+ hook_action_public,
953
+ upsert_hook
856
954
  };
package/dist/index.d.ts CHANGED
@@ -1,11 +1,11 @@
1
- import { G as PostListParams, T as PostsResponse, x as Post, D as PostCreate, Q as PostUpdate, Z as VersionInfo, y as PostContent, C as Category, k as CategoryCreate, A as AccessKey } from './types.d-BhWQru2j.js';
2
- import { ai as Profile, u as CreateProfileInput, aw as UpdateProfileInput, aj as ProfileFilter, c as AddFilterInput, aq as Timeline, A as Account, ae as PlatformSettings } from './types.d-ip2SzstN.js';
1
+ import { G as PostListParams, T as PostsResponse, x as Post, D as PostCreate, Q as PostUpdate, Z as VersionInfo, y as PostContent, C as Category, k as CategoryCreate, A as AccessKey } from './types.d-BEtzx3lu.js';
2
+ import { ai as Profile, u as CreateProfileInput, aw as UpdateProfileInput, aj as ProfileFilter, c as AddFilterInput, aq as Timeline, A as Account, ae as PlatformSettings } from './types.d-CK6qaT-O.js';
3
3
  import { z } from 'zod';
4
- import { a as ApiKey, q as Project, a7 as UpsertProject, G as GetConfigResult, S as SaveConfigRequest, W as TodoUpdate, H as HistoryAction, M as Milestone, i as Goal, V as TaskWithDetails, aa as UpsertTodo, a8 as UpsertTag, F as Task, L as TaskLink, C as ClaimRequest, h as DoneRequest, a9 as UpsertTaskLink, d as ApplyRequest, c as ApplyOp, B as TagWithTypedColor, D as DashboardResponse, o as PipelineRun, p as PipelineStageEvent, l as PipelineGrant, n as PipelinePackage, P as PipelineAnalysisTemplate, m as PipelineOidcTrust } from './types.d-BJ3g4B0G.js';
5
- export { r as ProjectConfig } from './types.d-BJ3g4B0G.js';
4
+ import { a as ApiKey, y as Project, ag as UpsertProject, G as GetConfigResult, S as SaveConfigRequest, a2 as TodoUpdate, H as HistoryAction, M as Milestone, j as Goal, k as Hook, q as HookTrigger, m as HookActionPublic, a8 as UpsertHook, o as HookDelivery, a1 as TaskWithDetails, aj as UpsertTodo, ah as UpsertTag, W as Task, Z as TaskLink, C as ClaimRequest, h as DoneRequest, ai as UpsertTaskLink, d as ApplyRequest, c as ApplyOp, V as TagWithTypedColor, D as DashboardResponse, w as PipelineRun, x as PipelineStageEvent, t as PipelineGrant, v as PipelinePackage, P as PipelineAnalysisTemplate, u as PipelineOidcTrust } from './types.d-NajL6dL5.js';
5
+ export { z as ProjectConfig } from './types.d-NajL6dL5.js';
6
6
  import { Result } from '@f0rbit/corpus';
7
7
  export { Result, err, ok } from '@f0rbit/corpus';
8
- import { C as CompletedVia, S as StageEventKind } from './schema.d-DfzLWuRW.js';
8
+ import { H as HookDeliveryStatus, C as CompletedVia, S as StageEventKind } from './schema.d-CFQELmTM.js';
9
9
  import 'drizzle-orm';
10
10
  import './media.d-R87HGuRp.js';
11
11
  import 'drizzle-orm/sqlite-core';
@@ -678,6 +678,11 @@ type ApiResultError = {
678
678
  type ApiResult<T> = Result<T, ApiResultError>;
679
679
  declare function wrap<T>(fn: () => Promise<T>): Promise<ApiResult<T>>;
680
680
 
681
+ /** Wire shape returned by every hooks route — `secret_encrypted` never round-trips (see `packages/core/src/services/hooks/registry.ts`'s `PublicHook`). */
682
+ type PublicHook = Omit<Hook, "action" | "trigger"> & {
683
+ trigger: HookTrigger;
684
+ action: HookActionPublic;
685
+ };
681
686
  type ReadyResponse = {
682
687
  items: Task[];
683
688
  next_cursor: string | null;
@@ -804,6 +809,7 @@ declare class ApiClient {
804
809
  create: (input?: string | {
805
810
  name?: string;
806
811
  scope?: "devpad" | "blog" | "media" | "pulse" | "all";
812
+ project_id?: string;
807
813
  }) => Promise<ApiResult<{
808
814
  message: string;
809
815
  key: {
@@ -953,6 +959,18 @@ declare class ApiClient {
953
959
  */
954
960
  goals: (id: string) => Promise<ApiResult<Goal[]>>;
955
961
  };
962
+ /**
963
+ * Hooks namespace (task A3.2) — automation registry + delivery ledger.
964
+ * Webhook secrets are write-only: `secret_encrypted` never round-trips.
965
+ */
966
+ readonly hooks: {
967
+ list: (project_id: string) => Promise<ApiResult<PublicHook[]>>;
968
+ upsert: (data: UpsertHook) => Promise<ApiResult<PublicHook>>;
969
+ delete: (id: string) => Promise<ApiResult<{
970
+ success: boolean;
971
+ }>>;
972
+ deliveries: (id: string, status?: HookDeliveryStatus) => Promise<ApiResult<HookDelivery[]>>;
973
+ };
956
974
  /**
957
975
  * Goals namespace with Result-wrapped operations
958
976
  */
@@ -1735,4 +1753,4 @@ declare const tools: Record<string, ToolDefinition>;
1735
1753
  declare const toolNames: string[];
1736
1754
  declare function getTool(name: string): ToolDefinition | undefined;
1737
1755
 
1738
- export { AccessKey, Account, AddFilterInput, ApiClient, ApiError, type ApiResult, type ApiResultError, type AuthMode, AuthenticationError, Category, CategoryCreate, CreateProfileInput, NetworkError, PlatformSettings, Post, PostContent, PostCreate, PostListParams, PostUpdate, PostsResponse, Profile, ProfileFilter, Project, type PulseErrorIssue, type PulseErrorsResult, type PulseEventRow, type PulseEventsPage, type PulseLatencyByMinute, type PulseLatencyResult, type PulseLogsResult, type PulseSummary, type PulseSummaryByDay, type RequestHistoryEntry, type RequestOptions, SaveConfigRequest, Task, TaskWithDetails, Timeline, type ToolDefinition, UpdateProfileInput, UpsertProject, UpsertTag, UpsertTodo, ValidationError, VersionInfo, ApiClient as default, getTool, getUserFriendlyErrorMessage, parseZodErrors, pulseSummaryHasData, toolNames, tools, wrap };
1756
+ export { AccessKey, Account, AddFilterInput, ApiClient, ApiError, type ApiResult, type ApiResultError, type AuthMode, AuthenticationError, Category, CategoryCreate, CreateProfileInput, NetworkError, PlatformSettings, Post, PostContent, PostCreate, PostListParams, PostUpdate, PostsResponse, Profile, ProfileFilter, Project, type PublicHook, type PulseErrorIssue, type PulseErrorsResult, type PulseEventRow, type PulseEventsPage, type PulseLatencyByMinute, type PulseLatencyResult, type PulseLogsResult, type PulseSummary, type PulseSummaryByDay, type RequestHistoryEntry, type RequestOptions, SaveConfigRequest, Task, TaskWithDetails, Timeline, type ToolDefinition, UpdateProfileInput, UpsertProject, UpsertTag, UpsertTodo, ValidationError, VersionInfo, ApiClient as default, getTool, getUserFriendlyErrorMessage, parseZodErrors, pulseSummaryHasData, toolNames, tools, wrap };
package/dist/index.js CHANGED
@@ -5,11 +5,12 @@ import {
5
5
  save_config_request,
6
6
  save_tags_request,
7
7
  upsert_goal,
8
+ upsert_hook,
8
9
  upsert_milestone,
9
10
  upsert_project,
10
11
  upsert_task_link,
11
12
  upsert_todo
12
- } from "./chunk-XHTCNYWS.js";
13
+ } from "./chunk-A7B2SE7T.js";
13
14
  import {
14
15
  CategoryCreateSchema,
15
16
  PostCreateSchema,
@@ -740,6 +741,20 @@ var ApiClient2 = class {
740
741
  */
741
742
  goals: (id) => wrap(() => this.clients.milestones.get(`/milestones/${id}/goals`))
742
743
  };
744
+ /**
745
+ * Hooks namespace (task A3.2) — automation registry + delivery ledger.
746
+ * Webhook secrets are write-only: `secret_encrypted` never round-trips.
747
+ */
748
+ this.hooks = {
749
+ list: (project_id) => wrap(() => this.clients.hooks.get("/hooks", { query: { project_id } })),
750
+ upsert: (data) => wrap(
751
+ () => data.id ? this.clients.hooks.patch(`/hooks/${data.id}`, { body: data }) : this.clients.hooks.post("/hooks", { body: data })
752
+ ),
753
+ delete: (id) => wrap(() => this.clients.hooks.delete(`/hooks/${id}`)),
754
+ deliveries: (id, status) => wrap(
755
+ () => this.clients.hooks.get(`/hooks/${id}/deliveries`, status ? { query: { status } } : {})
756
+ )
757
+ };
743
758
  /**
744
759
  * Goals namespace with Result-wrapped operations
745
760
  */
@@ -1544,7 +1559,8 @@ var ApiClient2 = class {
1544
1559
  blog: new ApiClient({ ...clientOptions, category: "blog" }),
1545
1560
  media: new ApiClient({ ...clientOptions, category: "media" }),
1546
1561
  pulse: new ApiClient({ ...clientOptions, base_url: `${base_url}/pulse`, category: "pulse" }),
1547
- pipelines: new ApiClient({ ...clientOptions, category: "pipelines" })
1562
+ pipelines: new ApiClient({ ...clientOptions, category: "pipelines" }),
1563
+ hooks: new ApiClient({ ...clientOptions, category: "hooks" })
1548
1564
  };
1549
1565
  }
1550
1566
  /**
@@ -1648,6 +1664,16 @@ var milestone_by_id = z2.object({
1648
1664
  var goal_by_id = z2.object({
1649
1665
  id: z2.string().describe("Goal ID")
1650
1666
  });
1667
+ var hook_filters = z2.object({
1668
+ project_id: z2.string().describe("Project ID to list hooks for")
1669
+ });
1670
+ var hook_by_id = z2.object({
1671
+ id: z2.string().describe("Hook ID")
1672
+ });
1673
+ var hook_deliveries_input = z2.object({
1674
+ id: z2.string().describe("Hook ID"),
1675
+ status: z2.enum(["pending", "delivered", "failed_transient", "failed_permanent"]).optional().describe("Filter by delivery status \u2014 use failed_permanent to see the DLQ")
1676
+ });
1651
1677
  var github_branches = z2.object({
1652
1678
  owner: z2.string().describe("Repository owner"),
1653
1679
  repo: z2.string().describe("Repository name")
@@ -1750,6 +1776,31 @@ var tools = {
1750
1776
  })
1751
1777
  )
1752
1778
  }),
1779
+ // Hooks (task A3.2) — project-scoped automation registry + delivery ledger
1780
+ devpad_hooks_list: define_tool({
1781
+ name: "devpad_hooks_list",
1782
+ description: "List hooks configured for a project",
1783
+ inputSchema: hook_filters,
1784
+ execute: async (client, input) => unwrap(await client.hooks.list(input.project_id))
1785
+ }),
1786
+ devpad_hooks_upsert: define_tool({
1787
+ name: "devpad_hooks_upsert",
1788
+ description: "Create or update a hook (webhook/vault/pipeline action fired on matching task_event kinds). Pass 'id' to update.",
1789
+ inputSchema: upsert_hook,
1790
+ execute: async (client, input) => unwrap(await client.hooks.upsert(input))
1791
+ }),
1792
+ devpad_hooks_delete: define_tool({
1793
+ name: "devpad_hooks_delete",
1794
+ description: "Delete a hook",
1795
+ inputSchema: hook_by_id,
1796
+ execute: async (client, input) => unwrap(await client.hooks.delete(input.id))
1797
+ }),
1798
+ devpad_hooks_deliveries: define_tool({
1799
+ name: "devpad_hooks_deliveries",
1800
+ description: "List delivery attempts for a hook, optionally filtered by status (the DLQ is status=failed_permanent)",
1801
+ inputSchema: hook_deliveries_input,
1802
+ execute: async (client, input) => unwrap(await client.hooks.deliveries(input.id, input.status))
1803
+ }),
1753
1804
  // Goals
1754
1805
  devpad_goals_list: define_tool({
1755
1806
  name: "devpad_goals_list",