@snagset/server 0.1.55 → 0.1.56

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.
Files changed (94) hide show
  1. package/dist/app.js +3 -0
  2. package/dist/app.js.map +1 -1
  3. package/dist/config.generated.js +2 -1
  4. package/dist/config.generated.js.map +1 -1
  5. package/dist/db/migrations/0019_trello_provider.no-txn.sql +11 -0
  6. package/dist/integrations/inbound.js +2 -0
  7. package/dist/integrations/inbound.js.map +1 -1
  8. package/dist/integrations/outbox.js +22 -3
  9. package/dist/integrations/outbox.js.map +1 -1
  10. package/dist/integrations/store.js +2 -2
  11. package/dist/integrations/store.js.map +1 -1
  12. package/dist/integrations/trello.js +147 -0
  13. package/dist/integrations/trello.js.map +1 -0
  14. package/dist/jobs/set.js +2 -0
  15. package/dist/jobs/set.js.map +1 -1
  16. package/dist/routes/integrations.js +181 -6
  17. package/dist/routes/integrations.js.map +1 -1
  18. package/dist/routes/threads.js.map +1 -1
  19. package/package.json +1 -1
  20. package/static/dashboard/assets/{CompositeItem-CvulL3yx.js → CompositeItem-B0Gv-UGy.js} +1 -1
  21. package/static/dashboard/assets/{CompositeList-Cc2N74pm.js → CompositeList-DJzkqbsI.js} +1 -1
  22. package/static/dashboard/assets/{ConfirmDialog-U7sGR-7r.js → ConfirmDialog-DrJjmykZ.js} +1 -1
  23. package/static/dashboard/assets/{CopyButton-BPRG72bK.js → CopyButton-N4ZGq5sM.js} +1 -1
  24. package/static/dashboard/assets/{FieldItemContext-BB4olvUX.js → FieldItemContext-Btlb65DI.js} +1 -1
  25. package/static/dashboard/assets/{InstallTag-07IMzmgd.js → InstallTag-ErmrqxJG.js} +1 -1
  26. package/static/dashboard/assets/{InstanceRows-2HV0g2Tc.js → InstanceRows-qItZIB6E.js} +1 -1
  27. package/static/dashboard/assets/{McpTokens-j7R5vQdJ.js → McpTokens-BANlGby-.js} +1 -1
  28. package/static/dashboard/assets/{Picker-DWjVDWI6.js → Picker-BGDXZjRG.js} +1 -1
  29. package/static/dashboard/assets/{SaveState-BhDPRdEB.js → SaveState-C5sUD5wu.js} +1 -1
  30. package/static/dashboard/assets/{_app-CsF903Bg.js → _app-Bskz-yjz.js} +1 -1
  31. package/static/dashboard/assets/{_app-CmSSR7Fr.js → _app-QhVaTUQt.js} +1 -1
  32. package/static/dashboard/assets/{activity-CiElrW9b.js → activity-RabDpuwi.js} +1 -1
  33. package/static/dashboard/assets/{arrow-left-BpbzTF1L.js → arrow-left-DJWxyBo6.js} +1 -1
  34. package/static/dashboard/assets/{avatar-B1TDu8wQ.js → avatar-CN3-8DpI.js} +1 -1
  35. package/static/dashboard/assets/{badge-DNL0s8ND.js → badge-C54dE8rx.js} +1 -1
  36. package/static/dashboard/assets/{card-BV6fjgTi.js → card-Dxk95cVf.js} +1 -1
  37. package/static/dashboard/assets/{check-nWqm4QA9.js → check-CK4ao5He.js} +1 -1
  38. package/static/dashboard/assets/{chevron-down-B0SxNOjK.js → chevron-down-OtEbsKDP.js} +1 -1
  39. package/static/dashboard/assets/{chevron-right-5IvSSfyx.js → chevron-right-DsIeYYan.js} +1 -1
  40. package/static/dashboard/assets/{copy-BlkC45lz.js → copy-oQJtUs23.js} +1 -1
  41. package/static/dashboard/assets/{createBaseUIEventDetails-DJQs5QD1.js → createBaseUIEventDetails-CtitjO53.js} +1 -1
  42. package/static/dashboard/assets/{dialog-wNx4TYmI.js → dialog-PoGeAS0T.js} +1 -1
  43. package/static/dashboard/assets/{dropdown-menu-Dg6I8B9T.js → dropdown-menu-CnT2RuY9.js} +1 -1
  44. package/static/dashboard/assets/{forgot-BskfFbWy.js → forgot-C2yLPZRe.js} +1 -1
  45. package/static/dashboard/assets/{getPseudoElementBounds-BI6SgJKV.js → getPseudoElementBounds-1HRS6at-.js} +1 -1
  46. package/static/dashboard/assets/{image-off-CmXQl4Bm.js → image-off-DUeMoP3X.js} +1 -1
  47. package/static/dashboard/assets/{index-DJIyUCPa.js → index-DCtWnS4U.js} +3 -3
  48. package/static/dashboard/assets/{inertValue-DFM3yqxg.js → inertValue-DvQ1EW5I.js} +1 -1
  49. package/static/dashboard/assets/{invite-Gb1SSWEm.js → invite-CGRft1Wf.js} +1 -1
  50. package/static/dashboard/assets/{label-BO35zXgP.js → label-Br7CuW71.js} +1 -1
  51. package/static/dashboard/assets/{layout-grid-DHSlCLw7.js → layout-grid-D8FSCXx_.js} +1 -1
  52. package/static/dashboard/assets/me-Bz7e5FMG.js +1 -0
  53. package/static/dashboard/assets/{parts-Cf55Yb70.js → parts-BE9o8mAH.js} +1 -1
  54. package/static/dashboard/assets/{plus-AlvHtj_r.js → plus-CZbLvWG1.js} +1 -1
  55. package/static/dashboard/assets/{reset-VLjsnDUf.js → reset-ZYeb2Axs.js} +1 -1
  56. package/static/dashboard/assets/{s._site-BOIQF8cS.js → s._site-DT0FXe9C.js} +1 -1
  57. package/static/dashboard/assets/s._site.comments-Ci3k9e5e.js +49 -0
  58. package/static/dashboard/assets/{s._site.reviewers-C2y2wYcP.js → s._site.reviewers-CMYsq2DL.js} +1 -1
  59. package/static/dashboard/assets/{s._site.settings-Cp8YeA4h.js → s._site.settings-CWNTmj8T.js} +1 -1
  60. package/static/dashboard/assets/{setup-DZSbxR5u.js → setup-C7sY4SXb.js} +1 -1
  61. package/static/dashboard/assets/{sign-in-BP-OTd-h.js → sign-in-DzeEwdj0.js} +1 -1
  62. package/static/dashboard/assets/{sign-up-Jei-X8L6.js → sign-up-iJvFq_R3.js} +1 -1
  63. package/static/dashboard/assets/{sites-nxU5wRJD.js → sites-DiBJvBBN.js} +1 -1
  64. package/static/dashboard/assets/studio-CK_HRLS5.js +1 -0
  65. package/static/dashboard/assets/{studio-BXjjp00e.js → studio-QR3vjisG.js} +1 -1
  66. package/static/dashboard/assets/{studio.index-5Z2JWyir.js → studio.index-B2WSVF56.js} +1 -1
  67. package/static/dashboard/assets/studio.integrations-BYz4cDCb.js +16 -0
  68. package/static/dashboard/assets/{studio.members-UOCj4scg.js → studio.members-DPqoth_D.js} +1 -1
  69. package/static/dashboard/assets/{studio.plan-CXzTImV1.js → studio.plan-C3t2S9GZ.js} +1 -1
  70. package/static/dashboard/assets/{sun-DhMBVtvb.js → sun-ChMFVIDA.js} +1 -1
  71. package/static/dashboard/assets/{switch-BbV1tcPM.js → switch-D0flLg1r.js} +1 -1
  72. package/static/dashboard/assets/{table-BlJV8zDx.js → table-PCTyuzaU.js} +1 -1
  73. package/static/dashboard/assets/{useAriaLabelledBy-DfnIJQvt.js → useAriaLabelledBy-Bu-GFL0B.js} +1 -1
  74. package/static/dashboard/assets/{useBaseQuery-ic0hLoWO.js → useBaseQuery-Cw1dAAOb.js} +1 -1
  75. package/static/dashboard/assets/{useCompositeItem-Dj-Nx-92.js → useCompositeItem-CHXWc-fj.js} +1 -1
  76. package/static/dashboard/assets/useQuery-B9Vos2vJ.js +1 -0
  77. package/static/dashboard/assets/useRender-BJibc2kV.js +1 -0
  78. package/static/dashboard/assets/{useScrollLock-tzg3KUOw.js → useScrollLock-d8peZTpK.js} +1 -1
  79. package/static/dashboard/assets/{useValueChanged-S18DT6ky.js → useValueChanged-CEhqkcjS.js} +1 -1
  80. package/static/dashboard/assets/{users-CklOnVh9.js → users-DGXcs62X.js} +1 -1
  81. package/static/dashboard/assets/{welcome-DmIcYw0Y.js → welcome-FVEqWF-E.js} +1 -1
  82. package/static/dashboard/assets/{widget-signin-B3lImWqb.js → widget-signin-CDnZ1WcR.js} +1 -1
  83. package/static/dashboard/assets/{you-CIO1vIEc.js → you-DaUXbySS.js} +1 -1
  84. package/static/dashboard/assets/{zod-C59-1wE1.js → zod-Cs-QZqu7.js} +1 -1
  85. package/static/dashboard/index.html +1 -1
  86. package/static/widget/build.json +2 -2
  87. package/static/widget/snag.js +1 -1
  88. package/static/widget/snag.runtime.js +1 -1
  89. package/static/dashboard/assets/me-Bu3DC102.js +0 -1
  90. package/static/dashboard/assets/s._site.comments-CTk77ILo.js +0 -49
  91. package/static/dashboard/assets/studio-C1Um7zxi.js +0 -1
  92. package/static/dashboard/assets/studio.integrations-BjFXv6iz.js +0 -16
  93. package/static/dashboard/assets/useQuery-qBadQDJJ.js +0 -1
  94. package/static/dashboard/assets/useRender-TrgqqhB3.js +0 -1
@@ -0,0 +1,147 @@
1
+ import { createHmac, timingSafeEqual } from "node:crypto";
2
+ export class TrelloError extends Error {
3
+ status;
4
+ retryable;
5
+ constructor(status, message) {
6
+ super(message);
7
+ this.status = status;
8
+ this.retryable = status >= 500 || status === 429;
9
+ }
10
+ }
11
+ export function trelloClient(opts) {
12
+ const base = (opts.apiBase ?? "https://api.trello.com/1").replace(/\/+$/, "");
13
+ const f = opts.fetch ?? globalThis.fetch;
14
+ const q = (s) => s.replace(/["\\]/g, "");
15
+ const auth = `OAuth oauth_consumer_key="${q(opts.apiKey)}", oauth_token="${q(opts.token)}"`;
16
+ async function call(method, path, body) {
17
+ let res;
18
+ try {
19
+ res = await f(`${base}${path}`, {
20
+ method,
21
+ headers: { authorization: auth, accept: "application/json", "user-agent": "snagset", ...(body ? { "content-type": "application/json" } : {}) },
22
+ ...(body ? { body: JSON.stringify(body) } : {}),
23
+ });
24
+ }
25
+ catch (e) {
26
+ throw new TrelloError(0, `could not reach Trello: ${e instanceof Error ? e.message : String(e)}`);
27
+ }
28
+ const text = await res.text().catch(() => "");
29
+ if (res.status === 401)
30
+ throw new TrelloError(401, "the API key and token were refused (revoked, expired, or from another key)");
31
+ if (res.status === 403)
32
+ throw new TrelloError(403, "the token is not allowed to do that on this board (it needs read and write)");
33
+ if (res.status === 404)
34
+ throw new TrelloError(404, "the board, list or card was not found, or the token cannot see it");
35
+ if (!res.ok)
36
+ throw new TrelloError(res.status, `Trello answered ${res.status}${text ? `: ${text.slice(0, 200)}` : ""}`);
37
+ if (!text)
38
+ return undefined;
39
+ try {
40
+ return JSON.parse(text);
41
+ }
42
+ catch {
43
+ throw new TrelloError(502, "Trello answered with something that is not JSON");
44
+ }
45
+ }
46
+ const fail = (e) => ({ ok: false, detail: e instanceof Error ? e.message : String(e) });
47
+ return {
48
+ /**
49
+ * What the connect dialog offers. With no board: who the token is and the
50
+ * open boards it can see. With a board: that board's open lists.
51
+ */
52
+ async discover(boardId) {
53
+ try {
54
+ const me = await call("GET", "/members/me?fields=fullName,username");
55
+ const who = me.fullName || me.username || "Trello";
56
+ if (boardId) {
57
+ const lists = await call("GET", `/boards/${encodeURIComponent(boardId)}/lists?filter=open&fields=name`);
58
+ return { ok: true, who, options: lists.map((l) => ({ value: l.id, label: l.name })) };
59
+ }
60
+ const boards = await call("GET", "/members/me/boards?filter=open&fields=name");
61
+ return { ok: true, who, options: boards.map((b) => ({ value: b.id, label: b.name })) };
62
+ }
63
+ catch (e) {
64
+ return fail(e);
65
+ }
66
+ },
67
+ /** The board and its three lists, checked: each list open, on that board, and the three distinct. */
68
+ async probe(boardId, lists) {
69
+ try {
70
+ const me = await call("GET", "/members/me?fields=fullName,username");
71
+ const board = await call("GET", `/boards/${encodeURIComponent(boardId)}?fields=name,url`);
72
+ const open = await call("GET", `/boards/${encodeURIComponent(boardId)}/lists?filter=open&fields=name`);
73
+ const ids = [lists.open, lists.progress, lists.resolved];
74
+ if (new Set(ids).size !== 3)
75
+ return { ok: false, detail: "pick three different lists: one each for open, in progress and resolved" };
76
+ const name = (id) => open.find((l) => l.id === id)?.name;
77
+ const missing = ids.find((id) => !name(id));
78
+ if (missing)
79
+ return { ok: false, detail: `the list ${missing} is not an open list on the board ${board.name}` };
80
+ return {
81
+ ok: true,
82
+ board: { id: board.id, name: board.name, url: board.url },
83
+ names: { open: name(lists.open), progress: name(lists.progress), resolved: name(lists.resolved) },
84
+ who: me.fullName || me.username || "Trello",
85
+ };
86
+ }
87
+ catch (e) {
88
+ return fail(e);
89
+ }
90
+ },
91
+ async createCard(input) {
92
+ const made = await call("POST", "/cards", {
93
+ idList: input.listId,
94
+ name: input.name.slice(0, 16384),
95
+ desc: input.desc.slice(0, 16384),
96
+ pos: "top",
97
+ });
98
+ return { id: made.id, url: made.shortUrl ?? made.url ?? "" };
99
+ },
100
+ async moveCard(cardId, listId) {
101
+ await call("PUT", `/cards/${encodeURIComponent(cardId)}`, { idList: listId });
102
+ },
103
+ /**
104
+ * The way back: a webhook on the board, owned by this token. Trello
105
+ * calls the address with HEAD first and refuses to register if it does
106
+ * not answer 200. One that already exists for the same address, board
107
+ * and token is found and reused rather than refused.
108
+ */
109
+ async registerWebhook(boardId, callbackURL) {
110
+ try {
111
+ const made = await call("POST", "/webhooks", { callbackURL, idModel: boardId, description: "Snagset" });
112
+ return { id: made.id };
113
+ }
114
+ catch (e) {
115
+ if (!(e instanceof TrelloError) || e.status !== 400 || !/already exists/i.test(e.message))
116
+ throw e;
117
+ const mine = await call("GET", `/tokens/${encodeURIComponent(opts.token)}/webhooks`);
118
+ const found = mine.find((w) => w.idModel === boardId && w.callbackURL === callbackURL);
119
+ if (!found)
120
+ throw e;
121
+ return { id: found.id };
122
+ }
123
+ },
124
+ async removeWebhook(id) {
125
+ await call("DELETE", `/webhooks/${encodeURIComponent(id)}`);
126
+ },
127
+ };
128
+ }
129
+ /**
130
+ * `X-Trello-Webhook` is the base64 HMAC-SHA1 of the raw body followed by the
131
+ * callback URL, keyed with the Power-Up's secret.
132
+ */
133
+ export function verifyTrelloSignature(raw, callbackURL, header, secret) {
134
+ if (!header)
135
+ return false;
136
+ const given = Buffer.from(header.trim(), "base64");
137
+ const want = createHmac("sha1", secret).update(raw + callbackURL, "utf8").digest();
138
+ return given.length === want.length && timingSafeEqual(given, want);
139
+ }
140
+ /** Our status → the list a card belongs in; a list → our status, or null for any other list. */
141
+ export function trelloListFor(status, lists) {
142
+ return status === "resolved" ? lists.resolved : status === "progress" || status === "review" ? lists.progress : lists.open;
143
+ }
144
+ export function statusForTrelloList(listId, lists) {
145
+ return listId === lists.resolved ? "resolved" : listId === lists.progress ? "progress" : listId === lists.open ? "open" : null;
146
+ }
147
+ //# sourceMappingURL=trello.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trello.js","sourceRo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UAAU,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,GAAG,GAAG,WAAW,EAAE,MAAM,CAAC,CAAC,MAAM,EAAE,CAAC;IACnF,OAAO,KAAK,CAAC,MAAM,KAAK,IAAI,CAAC,MAAM,IAAI,eAAe,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;AACtE,CAAC;AAED,gGAAgG;AAChG,MAAM,UAAU,aAAa,CAAC,MAAc,EAAE,KAAkB;IAC9D,OAAO,MAAM,KAAK,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,KAAK,UAAU,IAAI,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC;AAC7H,CAAC;AACD,MAAM,UAAU,mBAAmB,CAAC,MAAc,EAAE,KAAkB;IACpE,OAAO,MAAM,KAAK,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,KAAK,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,KAAK,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC;AACjI,CAAC"}
package/dist/jobs/set.js CHANGED
@@ -12,12 +12,14 @@ export function jobSet(d) {
12
12
  const githubApiBase = d.githubApiBase ?? d.cfg.get("SNAGSET_GITHUB_API_BASE");
13
13
  const linearApiBase = d.linearApiBase ?? d.cfg.get("SNAGSET_LINEAR_API_BASE");
14
14
  const slackApiBase = d.slackApiBase ?? d.cfg.get("SNAGSET_SLACK_API_BASE");
15
+ const trelloApiBase = d.trelloApiBase ?? d.cfg.get("SNAGSET_TRELLO_API_BASE");
15
16
  const push = {
16
17
  keys: d.keys,
17
18
  baseUrl: address,
18
19
  ...(githubApiBase ? { githubApiBase } : {}),
19
20
  ...(linearApiBase ? { linearApiBase } : {}),
20
21
  ...(slackApiBase ? { slackApiBase } : {}),
22
+ ...(trelloApiBase ? { trelloApiBase } : {}),
21
23
  jiraPrivate: d.cfg.bool("SNAGSET_JIRA_PRIVATE_ADDRESSES"),
22
24
  };
23
25
  // How the owner hears about comments. The registry validated it and
@@ -1 +1 @@
1
- {"version":3,"file":"set.js","sourceRoot":"","sources":["../../src/jobs/set.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAmB,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAiB,MAAM,2BAA2B,CAAC;AAC1E,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAmCrC,MAAM,UAAU,MAAM,CAAC,CAAa;IAClC,oEAAoE;IACpE,MAAM,OAAO,GAAG,aAAa,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC;IACpD,MAAM,aAAa,GAAG,CAAC,CAAC,aAAa,IAAI,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;IAC9E,MAAM,aAAa,GAAG,CAAC,CAAC,aAAa,IAAI,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;IAC9E,MAAM,YAAY,GAAG,CAAC,CAAC,YAAY,IAAI,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC;IAC3E,MAAM,IAAI,GAAa;QACrB,IAAI,EAAE,CAAC,CAAC,IAAI;QACZ,OAAO,EAAE,O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MAAM,SAAS,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC;YAChE;;;;;;;eAOG;YACH,MAAM,MAAM,GACV,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,MAAM,aAAa,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YAChG,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,MAAM,EAAE,GAAG,CAAC,MAAM,MAAM,EAAE,CAAC,CAAC,CAAC;QAC7D,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -5,6 +5,7 @@ import { githubClient } from "../integrations/github.js";
5
5
  import { linearClient, statusForLinearState, verifyLinearSignature } from "../integrations/linear.js";
6
6
  import { jiraClient, statusForJiraCategory, verifyJiraSignature } from "../integrations/jira.js";
7
7
  import { slackClient, slackManifest } from "../integrations/slack.js";
8
+ import { statusForTrelloList, trelloClient, verifyTrelloSignature } from "../integrations/trello.js";
8
9
  import { LimitReached, planLimitReached } from "../plan.js";
9
10
  import { getIntegration, isTracker, listIntegrations, markDelivered, replaceCredentials, markRefused, markIntegration, mintWebhookSecret, putIntegration, removeIntegration, trackerSecrets, REF_KIND, } from "../integrations/store.js";
10
11
  import { applyGitHubIssueEvent, applyIssueState, verifyGitHubSignature } from "../integrations/inbound.js";
@@ -17,20 +18,22 @@ function fail(c, status, code, message, details) {
17
18
  return c.json({ error: { code, message, ...(details ? { details } : {}), requestId: c.get("requestId") } }, status);
18
19
  }
19
20
  const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
20
- const NAME = { github: "GitHub", linear: "Linear", jira: "Jira", slack: "Slack" };
21
- /** What the card says when a delivery arrived but its signature did not match: the fix, in words. */
21
+ const NAME = { github: "GitHub", linear: "Linear", jira: "Jira", trello: "Trello", slack: "Slack" };
22
22
  /** Access checks a studio may make in a minute. */
23
23
  const DISCOVER_PER_MINUTE = 20;
24
+ /** What the card says when a delivery arrived but its signature did not match: the fix, in words. */
24
25
  const SIGNATURE_REFUSED = {
25
26
  github: "GitHub's delivery was signed with a different secret. Make a new secret here and give it to the repository's webhook.",
26
27
  linear: "Linear's delivery was signed with a different secret. Copy the signing secret from Linear's webhook and paste it here.",
27
28
  jira: "Jira's delivery was signed with a different secret. Give Jira's webhook the secret Snagset shows, or make a new one here.",
29
+ trello: "Trello's delivery was signed with a different secret. Copy the secret from your Power-Up's API key page in Trello and paste it here.",
28
30
  };
29
31
  export function integrationRoutes(deps) {
30
32
  const { sql, keys, projects } = deps;
31
33
  const app = new Hono();
32
34
  const webhookUrl = async (provider) => `${(await deps.baseUrl()).replace(/\/+$/, "")}/api/v1/integrations/${provider}/inbound`;
33
35
  const ghOpts = () => ({ ...(deps.push.githubApiBase ? { apiBase: deps.push.githubApiBase } : {}), ...(deps.push.fetch ? { fetch: deps.push.fetch } : {}) });
36
+ const trOpts = () => ({ ...(deps.push.trelloApiBase ? { apiBase: deps.push.trelloApiBase } : {}), ...(deps.push.fetch ? { fetch: deps.push.fetch } : {}) });
34
37
  const lnOpts = () => ({ ...(deps.push.linearApiBase ? { apiBase: deps.push.linearApiBase } : {}), ...(deps.push.fetch ? { fetch: deps.push.fetch } : {}) });
35
38
  const mustBeOwner = (c) => {
36
39
  const owner = c.get("owner");
@@ -54,7 +57,7 @@ export function integrationRoutes(deps) {
54
57
  };
55
58
  const provider = (c) => {
56
59
  const v = c.req.param("provider") ?? "";
57
- return isTracker(v) ? v : fail(c, 404, "integration_not_configured", `No tracker called ${JSON.stringify(v)}. This build speaks: github, linear, jira, slack.`);
60
+ return isTracker(v) ? v : fail(c, 404, "integration_not_configured", `No tracker called ${JSON.stringify(v)}. This build speaks: github, linear, jira, trello, slack.`);
58
61
  };
59
62
  /** The card's view of a connection — never a token. */
60
63
  const shape = (i, projectUid) => {
@@ -79,6 +82,10 @@ export function integrationRoutes(deps) {
79
82
  const cfg = i.config;
80
83
  return { provider: "jira", ...base, siteUrl: cfg.siteUrl, projectKey: cfg.projectKey, projectName: cfg.projectName, issueType: cfg.issueTypeName, email: cfg.email };
81
84
  }
85
+ if (i.provider === "trello") {
86
+ const cfg = i.config;
87
+ return { provider: "trello", ...base, boardName: cfg.boardName, boardUrl: cfg.boardUrl, listNames: cfg.listNames, webhookRegistered: !!cfg.webhookId };
88
+ }
82
89
  if (i.provider === "slack") {
83
90
  const cfg = i.config;
84
91
  return { provider: "slack", ...base, teamName: cfg.teamName, teamUrl: cfg.teamUrl, channelId: cfg.channelId, channelName: cfg.channelName };
@@ -176,6 +183,21 @@ export function integrationRoutes(deps) {
176
183
  const r = await linearClient({ apiKey, ...lnOpts() }).discover();
177
184
  return r.ok ? c.json({ who: r.who, options: r.options }) : fail(c, 422, "validation_failed", r.detail, { field: "apiKey" });
178
185
  }
186
+ if (pv === "trello") {
187
+ const apiKey = str("apiKey");
188
+ if (!apiKey)
189
+ return fail(c, 422, "validation_failed", "Paste your Power-Up's API key first.", { field: "apiKey" });
190
+ const token = str("token");
191
+ if (!token)
192
+ return fail(c, 422, "validation_failed", "Paste a token first — the Generate a token link makes one.", { field: "token" });
193
+ // A board id narrows the answer to that board's lists: the second
194
+ // half of the Connect step, asked once a board is picked.
195
+ const boardId = str("boardId");
196
+ if (boardId && !/^[0-9a-f]{24}$/i.test(boardId))
197
+ return fail(c, 422, "validation_failed", "That is not a Trello board id.", { field: "boardId" });
198
+ const r = await trelloClient({ apiKey, token, ...trOpts() }).discover(boardId || undefined);
199
+ return r.ok ? c.json({ who: r.who, options: r.options }) : fail(c, 422, "validation_failed", r.detail, { field: "token" });
200
+ }
179
201
  const siteUrl = str("siteUrl").replace(/\/+$/, "");
180
202
  if (!/^https?:\/\/[^\s/]+$/.test(siteUrl))
181
203
  return fail(c, 422, "validation_failed", "Give the site's address, like https://kilnwork.atlassian.net.", { field: "siteUrl" });
@@ -228,6 +250,72 @@ export function integrationRoutes(deps) {
228
250
  const createOn = body?.["createOn"] === "thread.created" ? "thread.created" : body?.["createOn"] === "manual" ? "manual" : pv === "slack" ? "thread.created" : "manual";
229
251
  const existing = await getIntegration(sql, keys, p.org_id, p.id, pv);
230
252
  const had = trackerSecrets(existing?.secret ?? null);
253
+ if (pv === "trello") {
254
+ // Trello (0.1.56): an API key and a token, a board, and three of its
255
+ // lists for open, in progress and resolved — probed before anything
256
+ // is stored. The way back is a webhook we register on the board
257
+ // ourselves; Trello signs deliveries with the Power-Up's secret, which
258
+ // the owner pastes on the next step (or here).
259
+ const prev = existing?.config;
260
+ const apiKey = str("apiKey") || prev?.apiKey || "";
261
+ if (!apiKey)
262
+ return fail(c, 422, "validation_failed", "Paste your Power-Up's API key.", { field: "apiKey" });
263
+ const token = str("token") || had.token || "";
264
+ if (!token)
265
+ return fail(c, 422, "validation_failed", "Paste a token — the Generate a token link makes one.", { field: "token" });
266
+ const boardId = str("boardId");
267
+ if (!/^[0-9a-f]{24}$/i.test(boardId))
268
+ return fail(c, 422, "validation_failed", "Pick a board.", { field: "boardId" });
269
+ const lists = { open: str("openList"), progress: str("progressList"), resolved: str("resolvedList") };
270
+ for (const [k, v] of Object.entries(lists)) {
271
+ if (!/^[0-9a-f]{24}$/i.test(v))
272
+ return fail(c, 422, "validation_failed", "Pick a list for open, in progress and resolved.", { field: `${k}List` });
273
+ }
274
+ const tc = trelloClient({ apiKey, token, ...trOpts() });
275
+ const probe = await tc.probe(boardId, lists);
276
+ if (!probe.ok)
277
+ return fail(c, 422, "validation_failed", `Trello: ${probe.detail}.`, { field: "boardId" });
278
+ const url = await webhookUrl("trello");
279
+ let webhookId = null;
280
+ let webhookError = null;
281
+ try {
282
+ webhookId = (await tc.registerWebhook(boardId, url)).id;
283
+ }
284
+ catch (e) {
285
+ // Trello checks the address with a HEAD before it registers, so a
286
+ // server it cannot reach (a laptop, a private network) lands here.
287
+ // The connection still works one way; the dialog says why the way
288
+ // back does not.
289
+ webhookError = e instanceof Error ? e.message : String(e);
290
+ }
291
+ // Re-registering on the same board failed: the webhook that was working
292
+ // stays, rather than being taken down with nothing in its place.
293
+ if (!webhookId && prev?.webhookId && prev.boardId === boardId)
294
+ webhookId = prev.webhookId;
295
+ // A board change leaves the old board's webhook behind: take it down,
296
+ // unless another connection holds the same webhook (one token, one
297
+ // board, one callback is one webhook at Trello).
298
+ if (prev?.webhookId && prev.webhookId !== webhookId && !(await webhookShared(prev.webhookId, p.id)))
299
+ await tc.removeWebhook(prev.webhookId).catch(() => { });
300
+ await putIntegration(sql, keys, {
301
+ orgId: p.org_id,
302
+ projectId: p.id,
303
+ provider: "trello",
304
+ config: {
305
+ apiKey,
306
+ boardId: probe.board.id,
307
+ boardName: probe.board.name,
308
+ boardUrl: probe.board.url,
309
+ lists,
310
+ listNames: probe.names,
311
+ webhookId,
312
+ createOn,
313
+ },
314
+ secret: JSON.stringify({ token, webhookSecret: str("webhookSecret") || had.webhookSecret }),
315
+ });
316
+ const i = await getIntegration(sql, keys, p.org_id, p.id, "trello");
317
+ return c.json({ integration: i ? shape(i, p.uid) : null, webhook: { url, registered: !!webhookId, ...(webhookError ? { error: webhookError } : {}) } });
318
+ }
231
319
  if (pv === "slack") {
232
320
  // Slack: a bot token from the app the operator created from our
233
321
  // manifest, and a channel by #name or id. Probed — the token, then the
@@ -385,6 +473,15 @@ export function integrationRoutes(deps) {
385
473
  const p = await site(c, owner);
386
474
  if (!p)
387
475
  return fail(c, 404, "project_not_found", "No project with that uid.");
476
+ if (pv === "trello") {
477
+ // The board's webhook is ours to take down; best effort, since a
478
+ // revoked token cannot, and Trello drops a webhook whose token goes.
479
+ const i = await getIntegration(sql, keys, p.org_id, p.id, "trello");
480
+ const cfg = i?.config;
481
+ const token = trackerSecrets(i?.secret ?? null).token;
482
+ if (cfg?.webhookId && token && !(await webhookShared(cfg.webhookId, p.id)))
483
+ await trelloClient({ apiKey: cfg.apiKey, token, ...trOpts() }).removeWebhook(cfg.webhookId).catch(() => { });
484
+ }
388
485
  await removeIntegration(sql, p.org_id, p.id, pv);
389
486
  return c.json({ integration: null });
390
487
  });
@@ -413,6 +510,11 @@ export function integrationRoutes(deps) {
413
510
  const r = await jiraClient({ siteUrl: cfg.siteUrl, email: cfg.email, apiToken: token, allowPrivate: !!deps.push.jiraPrivate, ...(deps.push.fetch ? { fetch: deps.push.fetch } : {}) }).probe(cfg.projectKey);
414
511
  ok = r.ok ? { ok: true, target: `${r.project.key} · ${r.project.name}` } : r;
415
512
  }
513
+ else if (pv === "trello") {
514
+ const cfg = i.config;
515
+ const r = await trelloClient({ apiKey: cfg.apiKey, token, ...trOpts() }).probe(cfg.boardId, cfg.lists);
516
+ ok = r.ok ? { ok: true, target: r.board.name } : r;
517
+ }
416
518
  else if (pv === "slack") {
417
519
  const cfg = i.config;
418
520
  try {
@@ -457,11 +559,15 @@ export function integrationRoutes(deps) {
457
559
  return fail(c, 409, "integration_not_configured", `${NAME[pv]} is not connected on this site.`);
458
560
  let secret;
459
561
  let show = true;
460
- if (pv === "linear") {
562
+ if (pv === "linear" || pv === "trello") {
563
+ // Theirs, not ours: Linear's webhook shows its signing secret, and
564
+ // Trello signs with the Power-Up's secret. Pasted, and never echoed.
461
565
  const body = (await c.req.json().catch(() => null));
462
566
  secret = typeof body?.["secret"] === "string" ? body["secret"].trim() : "";
463
- if (!secret)
464
- return fail(c, 422, "validation_failed", "Paste the signing secret Linear shows on the webhook.", { field: "secret" });
567
+ if (!secret) {
568
+ const how = pv === "linear" ? "Paste the signing secret Linear shows on the webhook." : "Paste the secret from your Power-Up's API key page in Trello.";
569
+ return fail(c, 422, "validation_failed", how, { field: "secret" });
570
+ }
465
571
  show = false;
466
572
  }
467
573
  else {
@@ -508,6 +614,11 @@ export function integrationRoutes(deps) {
508
614
  return where(tx);
509
615
  });
510
616
  const secretOf = (r) => trackerSecrets(r.credentials && r.credentials_iv ? open(keys, { ciphertext: r.credentials, iv: r.credentials_iv }) : null).webhookSecret;
617
+ /** Whether a live Trello connection on another site holds this webhook (Trello hands one token the same webhook for the same board and callback). */
618
+ const webhookShared = async (webhookId, exceptProjectId) => (await candidatesFor("trello", (tx) => tx `
619
+ SELECT id, org_id, project_id, credentials, credentials_iv FROM integrations
620
+ WHERE provider = 'trello' AND deleted_at IS NULL AND config->>'webhookId' = ${webhookId} AND project_id <> ${exceptProjectId}::uuid
621
+ `)).length > 0;
511
622
  /**
512
623
  * The tracker → us (05 endpoint 25c). Unauthenticated in the session
513
624
  * sense; authenticated by the provider's signature over the RAW body with
@@ -515,6 +626,10 @@ export function integrationRoutes(deps) {
515
626
  * pasted from Linear's form for Linear. The target named in the
516
627
  * payload picks the candidate connections; the signature picks the one.
517
628
  */
629
+ // Trello checks the address with a HEAD before it will register a webhook
630
+ // (and again from time to time). Nothing is read or written. Hono answers a
631
+ // HEAD from the GET route, so the route is a GET.
632
+ app.get("/api/v1/integrations/trello/inbound", (c) => c.body(null, 200));
518
633
  app.post("/api/v1/integrations/:provider/inbound", async (c) => {
519
634
  const pv = provider(c);
520
635
  if (pv instanceof Response)
@@ -624,6 +739,66 @@ export function integrationRoutes(deps) {
624
739
  await noticeIfResolved(applied, match.org_id, match.project_id, "Jira");
625
740
  return c.json({ ok: true, applied: applied.kind, ...("why" in applied ? { why: applied.why } : {}) });
626
741
  }
742
+ if (pv === "trello") {
743
+ // Trello (0.1.56): X-Trello-Webhook is the base64 HMAC-SHA1 of the raw
744
+ // body followed by the callback URL, keyed with the Power-Up's secret;
745
+ // the action's id is the replay key. The board picks the candidates.
746
+ const signature = c.req.header("x-trello-webhook");
747
+ const action = payload?.action;
748
+ const boardId = String(payload?.model?.id ?? action?.data?.board?.id ?? "");
749
+ if (!/^[0-9a-f]{24}$/i.test(boardId))
750
+ return fail(c, 400, "validation_failed", "The payload names no board.");
751
+ const callbackURL = await webhookUrl("trello");
752
+ const candidates = await candidatesFor("trello", (tx) => tx `
753
+ SELECT id, org_id, project_id, credentials, credentials_iv, config FROM integrations
754
+ WHERE provider = 'trello' AND deleted_at IS NULL AND enabled AND config->>'boardId' = ${boardId}
755
+ `);
756
+ // Several connections can share one board, and one Power-Up's secret
757
+ // (a studio's staging and live sites; one token's single webhook). The
758
+ // delivery is applied to EVERY connection it verifies for, each with
759
+ // its own ledger key: Trello's action id is the same in every
760
+ // webhook's delivery of that action, so a bare id would let one
761
+ // connection's delivery spend another's.
762
+ const matches = candidates.filter((r) => {
763
+ const s = secretOf(r);
764
+ return !!s && verifyTrelloSignature(raw, callbackURL, signature, s);
765
+ });
766
+ if (!matches.length) {
767
+ if (candidates.length === 1)
768
+ await markRefused(sql, candidates[0].id, SIGNATURE_REFUSED.trello);
769
+ return fail(c, 401, "provider_signature_invalid", "The signature does not match this board's secret — paste the Power-Up's secret from Trello into Snagset.");
770
+ }
771
+ const type = String(action?.type ?? "");
772
+ const cardId = String(action?.data?.card?.id ?? "");
773
+ const actionId = String(action?.id ?? "") || `${cardId}:${type}:${Date.now()}`;
774
+ let shown = null;
775
+ for (const match of matches) {
776
+ await markDelivered(sql, match.id);
777
+ const cfg = match.config;
778
+ let status = null;
779
+ if (type === "deleteCard")
780
+ status = "detach";
781
+ else if (type === "updateCard" && action?.data?.listAfter?.id)
782
+ status = statusForTrelloList(String(action.data.listAfter.id), cfg.lists);
783
+ if (!status || !cardId)
784
+ continue;
785
+ const applied = await applyIssueState(sql, {
786
+ provider: "trello",
787
+ orgId: match.org_id,
788
+ projectId: match.project_id,
789
+ deliveryId: `${match.id}:${actionId}`,
790
+ externalId: cardId,
791
+ status,
792
+ progressHoldsReview: true,
793
+ });
794
+ await noticeIfResolved(applied, match.org_id, match.project_id, "Trello");
795
+ if (!shown || (shown.kind === "ignored" && shown.why === "no-thread"))
796
+ shown = applied;
797
+ }
798
+ if (!shown)
799
+ return c.json({ ok: true, applied: "ignored", why: "action" });
800
+ return c.json({ ok: true, applied: shown.kind, ...("why" in shown ? { why: shown.why } : {}) });
801
+ }
627
802
  // Linear: Linear-Signature is the hex HMAC over the raw body
628
803
  // with the webhook's signing secret; Linear-Delivery is the replay key;
629
804
  // webhookTimestamp guards a captured body replayed much later.