convex-linear 0.0.1
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/LICENSE +201 -0
- package/README.md +438 -0
- package/dist/client/_generated/_ignore.d.ts +1 -0
- package/dist/client/_generated/_ignore.d.ts.map +1 -0
- package/dist/client/_generated/_ignore.js +3 -0
- package/dist/client/_generated/_ignore.js.map +1 -0
- package/dist/client/index.d.ts +163 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +316 -0
- package/dist/client/index.js.map +1 -0
- package/dist/component/_generated/api.d.ts +34 -0
- package/dist/component/_generated/api.d.ts.map +1 -0
- package/dist/component/_generated/api.js +31 -0
- package/dist/component/_generated/api.js.map +1 -0
- package/dist/component/_generated/component.d.ts +170 -0
- package/dist/component/_generated/component.d.ts.map +1 -0
- package/dist/component/_generated/component.js +11 -0
- package/dist/component/_generated/component.js.map +1 -0
- package/dist/component/_generated/dataModel.d.ts +46 -0
- package/dist/component/_generated/dataModel.d.ts.map +1 -0
- package/dist/component/_generated/dataModel.js +11 -0
- package/dist/component/_generated/dataModel.js.map +1 -0
- package/dist/component/_generated/server.d.ts +133 -0
- package/dist/component/_generated/server.d.ts.map +1 -0
- package/dist/component/_generated/server.js +80 -0
- package/dist/component/_generated/server.js.map +1 -0
- package/dist/component/convex.config.d.ts +3 -0
- package/dist/component/convex.config.d.ts.map +1 -0
- package/dist/component/convex.config.js +4 -0
- package/dist/component/convex.config.js.map +1 -0
- package/dist/component/lib.d.ts +146 -0
- package/dist/component/lib.d.ts.map +1 -0
- package/dist/component/lib.js +258 -0
- package/dist/component/lib.js.map +1 -0
- package/dist/component/schema.d.ts +75 -0
- package/dist/component/schema.d.ts.map +1 -0
- package/dist/component/schema.js +51 -0
- package/dist/component/schema.js.map +1 -0
- package/package.json +105 -0
- package/src/client/_generated/_ignore.ts +1 -0
- package/src/client/index.ts +460 -0
- package/src/client/setup.test.ts +26 -0
- package/src/component/_generated/api.ts +50 -0
- package/src/component/_generated/component.ts +224 -0
- package/src/component/_generated/dataModel.ts +60 -0
- package/src/component/_generated/server.ts +169 -0
- package/src/component/convex.config.ts +5 -0
- package/src/component/lib.test.ts +191 -0
- package/src/component/lib.ts +280 -0
- package/src/component/schema.ts +53 -0
- package/src/component/setup.test.ts +11 -0
- package/src/test.ts +18 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,438 @@
|
|
|
1
|
+
# convex-linear
|
|
2
|
+
|
|
3
|
+
Sync Linear issues and comments into your Convex database reactively, and create, update, comment on, and archive issues directly from Convex functions.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/convex-linear)
|
|
6
|
+
[](https://www.convex.dev/components/sholajegede/convex-linear)
|
|
7
|
+
[](https://www.npmjs.com/package/convex-linear)
|
|
8
|
+
[](./LICENSE)
|
|
9
|
+
|
|
10
|
+
```ts
|
|
11
|
+
const linear = new Linear(components.convexLinear, {
|
|
12
|
+
apiKey: process.env.LINEAR_API_KEY!,
|
|
13
|
+
webhookSecret: process.env.LINEAR_WEBHOOK_SECRET!,
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
// File an issue and get it back immediately — no waiting on the webhook
|
|
17
|
+
const { identifier, url } = await linear.createIssue(ctx, {
|
|
18
|
+
teamId: "team_...",
|
|
19
|
+
title: "Ship the launch checklist",
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// Every issue for that team stays live from here on, updated the
|
|
23
|
+
// instant something changes in Linear — including edits made outside
|
|
24
|
+
// your app, like someone archiving it from Linear's own UI
|
|
25
|
+
const issues = useQuery(api.example.listIssuesByTeam, { teamId: "team_..." });
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
<!-- START: Include on https://convex.dev/components -->
|
|
29
|
+
|
|
30
|
+
## What this does
|
|
31
|
+
|
|
32
|
+
`convex-linear` gives your Convex app a live, queryable mirror of Linear issues and comments for the teams you care about, kept up to date by Linear webhooks, plus a small set of actions for driving Linear from your own backend logic:
|
|
33
|
+
|
|
34
|
+
- **Reactive issue & comment tracking** — every `Issue` and `Comment` webhook event updates a Convex table, so `useQuery` in your React app re-renders the instant something changes in Linear.
|
|
35
|
+
- **Create, update, comment, archive** — call `createIssue`, `updateIssue`, `createComment`, `archiveIssue`, and `unarchiveIssue` from Convex actions using the Linear GraphQL API.
|
|
36
|
+
- **Idempotent by delivery ID** — every webhook delivery is recorded by its `Linear-Delivery` ID, so retried deliveries never double-process.
|
|
37
|
+
- **Signature and freshness verified** — every inbound webhook is verified against `Linear-Signature` with a constant-time HMAC-SHA256 comparison, and rejected if `Linear-Timestamp` is more than 60 seconds old, before anything is written.
|
|
38
|
+
|
|
39
|
+
This is a [Convex component](https://convex.dev/components): its `issues`, `comments`, and `webhookEvents` tables live in an isolated schema, not your app's schema, and are only reachable through the functions this component exposes.
|
|
40
|
+
|
|
41
|
+
## Table of Contents
|
|
42
|
+
|
|
43
|
+
- [Install](#install)
|
|
44
|
+
- [Quick Start](#quick-start)
|
|
45
|
+
- [Setup](#setup)
|
|
46
|
+
- [Usage](#usage)
|
|
47
|
+
- [API Reference](#api-reference)
|
|
48
|
+
- [Type Reference](#type-reference)
|
|
49
|
+
- [Webhook Events](#webhook-events)
|
|
50
|
+
- [Database Schema](#database-schema)
|
|
51
|
+
- [Authentication](#authentication)
|
|
52
|
+
- [Example App](#example-app)
|
|
53
|
+
- [Testing](#testing)
|
|
54
|
+
- [Limitations](#limitations)
|
|
55
|
+
- [Troubleshooting](#troubleshooting)
|
|
56
|
+
- [Contributing](#contributing)
|
|
57
|
+
- [Changelog](#changelog)
|
|
58
|
+
|
|
59
|
+
## Install
|
|
60
|
+
|
|
61
|
+
```sh
|
|
62
|
+
npm install convex-linear
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Quick Start
|
|
66
|
+
|
|
67
|
+
### 1. Add the component
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
// convex/convex.config.ts
|
|
71
|
+
import { defineApp } from "convex/server";
|
|
72
|
+
import convexLinear from "convex-linear/convex.config";
|
|
73
|
+
|
|
74
|
+
const app = defineApp();
|
|
75
|
+
app.use(convexLinear);
|
|
76
|
+
|
|
77
|
+
export default app;
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### 2. Set environment variables
|
|
81
|
+
|
|
82
|
+
```sh
|
|
83
|
+
npx convex env set LINEAR_API_KEY lin_api_...
|
|
84
|
+
npx convex env set LINEAR_WEBHOOK_SECRET whsec_...
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
`LINEAR_API_KEY` is a personal API key (Settings → API → Personal API keys) or an OAuth access token. `LINEAR_WEBHOOK_SECRET` is the signing secret shown when you create the webhook in step 4.
|
|
88
|
+
|
|
89
|
+
### 3. Mount the webhook handler
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
// convex/http.ts
|
|
93
|
+
import { httpRouter } from "convex/server";
|
|
94
|
+
import { components } from "./_generated/api";
|
|
95
|
+
import { Linear } from "convex-linear";
|
|
96
|
+
|
|
97
|
+
const linear = new Linear(components.convexLinear, {
|
|
98
|
+
apiKey: process.env.LINEAR_API_KEY!,
|
|
99
|
+
webhookSecret: process.env.LINEAR_WEBHOOK_SECRET!,
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
const http = httpRouter();
|
|
103
|
+
|
|
104
|
+
http.route({
|
|
105
|
+
path: "/webhooks/linear",
|
|
106
|
+
method: "POST",
|
|
107
|
+
handler: linear.webhookHandler,
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
export default http;
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### 4. Register the webhook in Linear
|
|
114
|
+
|
|
115
|
+
In your workspace's **Settings → API → Webhooks**, add a webhook pointing at `https://<your-deployment>.convex.site/webhooks/linear`, and subscribe to the **Issues** and **Comments** resource types. Copy the signing secret Linear shows you into `LINEAR_WEBHOOK_SECRET`.
|
|
116
|
+
|
|
117
|
+
### 5. Initialize the client
|
|
118
|
+
|
|
119
|
+
```ts
|
|
120
|
+
// convex/example.ts
|
|
121
|
+
import { action, query } from "./_generated/server";
|
|
122
|
+
import { components } from "./_generated/api";
|
|
123
|
+
import { Linear } from "convex-linear";
|
|
124
|
+
import { v } from "convex/values";
|
|
125
|
+
|
|
126
|
+
const linear = new Linear(components.convexLinear, {
|
|
127
|
+
apiKey: process.env.LINEAR_API_KEY!,
|
|
128
|
+
webhookSecret: process.env.LINEAR_WEBHOOK_SECRET!,
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
export const listIssuesByTeam = query({
|
|
132
|
+
args: { teamId: v.string() },
|
|
133
|
+
handler: async (ctx, args) => {
|
|
134
|
+
return await linear.listIssuesByTeam(ctx, args);
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Setup
|
|
140
|
+
|
|
141
|
+
The component needs no schema changes in your app — its tables (`issues`, `comments`, `webhookEvents`) live entirely inside the component's own isolated schema. All you need is the webhook mounted (step 3 above) and a `Linear` client instance wherever you call its methods.
|
|
142
|
+
|
|
143
|
+
Issues and comments are keyed by Linear's own UUID `id` field, not by the human-readable identifier (e.g. `"ENG-123"`) — identifiers are stored too and are what you'd show in a UI, but lookups and upserts go through the UUID since that's what's stable across a team's issue-numbering changes.
|
|
144
|
+
|
|
145
|
+
## Usage
|
|
146
|
+
|
|
147
|
+
### Create an issue
|
|
148
|
+
|
|
149
|
+
```ts
|
|
150
|
+
export const fileIssue = action({
|
|
151
|
+
args: {
|
|
152
|
+
teamId: v.string(),
|
|
153
|
+
title: v.string(),
|
|
154
|
+
description: v.optional(v.string()),
|
|
155
|
+
priority: v.optional(v.number()),
|
|
156
|
+
},
|
|
157
|
+
handler: async (ctx, args) => {
|
|
158
|
+
return await linear.createIssue(ctx, args);
|
|
159
|
+
},
|
|
160
|
+
});
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
Returns `{ identifier, url }` and immediately records the full issue in Convex — you don't have to wait for the webhook round-trip to see it in a query.
|
|
164
|
+
|
|
165
|
+
### Update an issue
|
|
166
|
+
|
|
167
|
+
```ts
|
|
168
|
+
export const reprioritize = action({
|
|
169
|
+
args: { issueId: v.string(), priority: v.number() },
|
|
170
|
+
handler: async (ctx, args) => {
|
|
171
|
+
await linear.updateIssue(ctx, args);
|
|
172
|
+
return null;
|
|
173
|
+
},
|
|
174
|
+
});
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
Pass a `stateId` (a workflow state's UUID, found via Linear's GraphQL API or the URL when viewing a team's workflow settings) to move an issue between states — Linear's states are custom per team, so there's no fixed `"open"`/`"closed"` enum the way there is for GitHub issues.
|
|
178
|
+
|
|
179
|
+
### Comment on an issue
|
|
180
|
+
|
|
181
|
+
```ts
|
|
182
|
+
export const comment = action({
|
|
183
|
+
args: { issueId: v.string(), body: v.string() },
|
|
184
|
+
handler: async (ctx, args) => {
|
|
185
|
+
return await linear.createComment(ctx, args);
|
|
186
|
+
},
|
|
187
|
+
});
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### Archive an issue
|
|
191
|
+
|
|
192
|
+
```ts
|
|
193
|
+
export const dismiss = action({
|
|
194
|
+
args: { issueId: v.string() },
|
|
195
|
+
handler: async (ctx, args) => {
|
|
196
|
+
await linear.archiveIssue(ctx, args);
|
|
197
|
+
return null;
|
|
198
|
+
},
|
|
199
|
+
});
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
Archiving in Linear is a separate concept from closing — an archived issue is hidden from active views but is not deleted; it stays restorable from Linear's own archives page. This component mirrors that: `archiveIssue` sets the issue's `archivedAt` field in Convex rather than deleting its row, so an archived issue keeps showing up in `getIssue`/`listIssuesByTeam` with `archivedAt` set, and you decide whether to filter it out of your UI.
|
|
203
|
+
|
|
204
|
+
**A note on how this is actually detected**, because it is not what you'd guess from Linear's docs alone: we tested this live against Linear's real API, and found that the `action` field on an `Issue` webhook delivery does *not* reliably indicate archived vs. trashed vs. deleted, and none of these deliveries carry `archivedAt` or `trashed` on their own payload:
|
|
205
|
+
|
|
206
|
+
| What happened | Webhook `action` you actually get |
|
|
207
|
+
| --- | --- |
|
|
208
|
+
| `issueArchive` (soft archive, restorable) | `remove` |
|
|
209
|
+
| `issueUnarchive` (restore from archive) | `restore` |
|
|
210
|
+
| Moved to Linear's 30-day trash (e.g. "Delete issue" in the UI) | `update` |
|
|
211
|
+
| Permanently gone (after 30 days in trash, or otherwise purged) | issue no longer exists at all |
|
|
212
|
+
|
|
213
|
+
Because of this, the webhook handler does not branch on `action` for `Issue` events at all — every delivery re-fetches the issue's current state directly from Linear's GraphQL API and mirrors that (`archivedAt` and `trashed` included). The `action` is still recorded on the `webhookEvents` row for your own auditing, but the *only* thing that triggers an actual `removeIssue` (a hard delete of the local row) is the re-fetch itself failing with "Entity not found" — meaning the issue is genuinely, permanently gone. This does mean one extra Linear API call per `Issue` webhook delivery; see [Limitations](#limitations).
|
|
214
|
+
|
|
215
|
+
### Unarchive an issue
|
|
216
|
+
|
|
217
|
+
```ts
|
|
218
|
+
export const restore = action({
|
|
219
|
+
args: { issueId: v.string() },
|
|
220
|
+
handler: async (ctx, args) => {
|
|
221
|
+
await linear.unarchiveIssue(ctx, args);
|
|
222
|
+
return null;
|
|
223
|
+
},
|
|
224
|
+
});
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
Restores the issue in Linear and clears `archivedAt` on its Convex row.
|
|
228
|
+
|
|
229
|
+
### Read issues and comments reactively
|
|
230
|
+
|
|
231
|
+
```tsx
|
|
232
|
+
const issues = useQuery(api.example.listIssuesByTeam, { teamId: "team_..." });
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
Every `Issue` and `Comment` webhook event patches, inserts, or removes a row, so this query re-renders live as issues move through your team's workflow — no polling.
|
|
236
|
+
|
|
237
|
+
## API Reference
|
|
238
|
+
|
|
239
|
+
### Actions (need `ctx` from an action)
|
|
240
|
+
|
|
241
|
+
| Method | Description |
|
|
242
|
+
| --- | --- |
|
|
243
|
+
| `createIssue(ctx, { teamId, title, description?, priority?, assigneeId?, labelIds? })` | Creates a new issue via the GraphQL API and records it. Returns `{ identifier, url }`. |
|
|
244
|
+
| `updateIssue(ctx, { issueId, title?, description?, stateId?, priority?, assigneeId?, labelIds? })` | Updates an issue's fields and re-records the full result. |
|
|
245
|
+
| `createComment(ctx, { issueId, body })` | Posts a comment on an issue. Returns `{ id }`. |
|
|
246
|
+
| `archiveIssue(ctx, { issueId })` | Archives an issue in Linear and sets `archivedAt` on its Convex row (the row is kept, not deleted). |
|
|
247
|
+
| `unarchiveIssue(ctx, { issueId })` | Restores an archived issue in Linear and clears `archivedAt` on its Convex row. |
|
|
248
|
+
|
|
249
|
+
### Queries (work from actions, queries, or mutations)
|
|
250
|
+
|
|
251
|
+
| Method | Description |
|
|
252
|
+
| --- | --- |
|
|
253
|
+
| `getIssue(ctx, { issueId })` | Fetch one issue by its Linear UUID. |
|
|
254
|
+
| `listIssuesByTeam(ctx, { teamId, limit? })` | Most recently updated issues for a team, newest first. |
|
|
255
|
+
| `listCommentsByIssue(ctx, { issueId, limit? })` | Most recently updated comments for an issue, newest first. |
|
|
256
|
+
|
|
257
|
+
### Webhook
|
|
258
|
+
|
|
259
|
+
| Property | Description |
|
|
260
|
+
| --- | --- |
|
|
261
|
+
| `webhookHandler` | An `httpAction` that verifies, deduplicates, and processes `Issue` and `Comment` webhook deliveries. Mount it at any route. |
|
|
262
|
+
|
|
263
|
+
## Type Reference
|
|
264
|
+
|
|
265
|
+
```ts
|
|
266
|
+
type LinearOptions = {
|
|
267
|
+
apiKey: string; // personal API key or OAuth access token
|
|
268
|
+
webhookSecret: string; // the signing secret configured on the Linear webhook
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
type CreateIssueArgs = {
|
|
272
|
+
teamId: string;
|
|
273
|
+
title: string;
|
|
274
|
+
description?: string;
|
|
275
|
+
priority?: number; // Linear's own scale: 0 none, 1 urgent, 2 high, 3 normal, 4 low
|
|
276
|
+
assigneeId?: string;
|
|
277
|
+
labelIds?: string[];
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
type UpdateIssueArgs = {
|
|
281
|
+
issueId: string;
|
|
282
|
+
title?: string;
|
|
283
|
+
description?: string;
|
|
284
|
+
stateId?: string; // a workflow state's UUID
|
|
285
|
+
priority?: number;
|
|
286
|
+
assigneeId?: string;
|
|
287
|
+
labelIds?: string[];
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
type Issue = {
|
|
291
|
+
issueId: string; // Linear's UUID
|
|
292
|
+
identifier: string; // e.g. "ENG-123"
|
|
293
|
+
teamId: string;
|
|
294
|
+
title: string;
|
|
295
|
+
description?: string;
|
|
296
|
+
state: string; // team-defined workflow state name
|
|
297
|
+
priority?: number;
|
|
298
|
+
assigneeId?: string;
|
|
299
|
+
assigneeName?: string;
|
|
300
|
+
labels?: string[];
|
|
301
|
+
url: string;
|
|
302
|
+
archivedAt?: number; // set when Linear has archived the issue; absent/undefined otherwise
|
|
303
|
+
trashed?: boolean; // set when the issue is in Linear's 30-day trash — distinct from archivedAt
|
|
304
|
+
createdAt: number;
|
|
305
|
+
updatedAt: number;
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
type Comment = {
|
|
309
|
+
commentId: string; // Linear's UUID
|
|
310
|
+
issueId: string;
|
|
311
|
+
body: string;
|
|
312
|
+
userId?: string;
|
|
313
|
+
userName?: string;
|
|
314
|
+
createdAt: number;
|
|
315
|
+
updatedAt: number;
|
|
316
|
+
};
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
## Webhook Events
|
|
320
|
+
|
|
321
|
+
The webhook handler subscribes to two Linear resource types (set these when creating the webhook):
|
|
322
|
+
|
|
323
|
+
- **`Issue`** — every delivery, regardless of its `action`, re-fetches the issue from Linear's API and upserts the result (including `archivedAt` and `trashed`); the row is only deleted if that re-fetch comes back "Entity not found" (the issue is genuinely, permanently gone). See [Archive an issue](#archive-an-issue) for why `action` alone can't be trusted here.
|
|
324
|
+
- **`Comment`** — `create`/`update` actions upsert the comment into the `comments` table; `remove` is ignored (there is no dependent state to clean up, so a removed comment is left as a stale row rather than chasing down a delete).
|
|
325
|
+
|
|
326
|
+
Every delivery is checked against `Linear-Signature` (HMAC-SHA256 of the raw request body, hex-encoded) with a constant-time comparison, checked for a `Linear-Timestamp` within 60 seconds of the current time (Linear's own recommendation against replay attacks), and deduplicated by `Linear-Delivery` before any table write.
|
|
327
|
+
|
|
328
|
+
Other resource types (`Project`, `Cycle`, `IssueLabel`, etc.) are accepted by the route but ignored after signature verification and idempotency recording, so you can subscribe to more events later without needing a new endpoint.
|
|
329
|
+
|
|
330
|
+
## Database Schema
|
|
331
|
+
|
|
332
|
+
```ts
|
|
333
|
+
issues: {
|
|
334
|
+
issueId: string; // indexed: by_issueId — Linear's UUID
|
|
335
|
+
identifier: string; // e.g. "ENG-123"
|
|
336
|
+
teamId: string; // indexed: by_teamId
|
|
337
|
+
title: string;
|
|
338
|
+
description?: string;
|
|
339
|
+
state: string;
|
|
340
|
+
priority?: number;
|
|
341
|
+
assigneeId?: string;
|
|
342
|
+
assigneeName?: string;
|
|
343
|
+
labels?: string[];
|
|
344
|
+
url: string;
|
|
345
|
+
archivedAt?: number; // set when Linear has archived the issue (not deleted)
|
|
346
|
+
trashed?: boolean; // set when the issue is in Linear's 30-day trash
|
|
347
|
+
createdAt: number;
|
|
348
|
+
updatedAt: number;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
comments: {
|
|
352
|
+
commentId: string; // indexed: by_commentId — Linear's UUID
|
|
353
|
+
issueId: string; // indexed: by_issueId
|
|
354
|
+
body: string;
|
|
355
|
+
userId?: string;
|
|
356
|
+
userName?: string;
|
|
357
|
+
createdAt: number;
|
|
358
|
+
updatedAt: number;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
webhookEvents: {
|
|
362
|
+
eventId: string; // indexed: by_eventId — Linear-Delivery
|
|
363
|
+
eventType: string; // Linear-Event: "Issue" | "Comment" | ...
|
|
364
|
+
action?: string; // payload.action: "create" | "update" | "remove" | "restore" — recorded for
|
|
365
|
+
// auditing only; see Webhook Events for why Issue events don't branch on it
|
|
366
|
+
payload: string; // raw JSON body, for auditing/replay
|
|
367
|
+
receivedAt: number;
|
|
368
|
+
}
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
This schema lives entirely inside the component's isolated namespace — it will never collide with tables in your app's own `convex/schema.ts`.
|
|
372
|
+
|
|
373
|
+
## Authentication
|
|
374
|
+
|
|
375
|
+
Linear's GraphQL API accepts two kinds of tokens in the `Authorization` header, and they are **not** sent the same way:
|
|
376
|
+
|
|
377
|
+
- A **personal API key** (the kind most integrations use, created under Settings → API) is sent as-is: `Authorization: lin_api_xxxxx` — no `Bearer ` prefix.
|
|
378
|
+
- An **OAuth access token** (from a full OAuth app) does use the standard `Authorization: Bearer <token>` form.
|
|
379
|
+
|
|
380
|
+
This component assumes a personal API key or an already-`Bearer`-formatted token is passed as `apiKey` — if you're using OAuth, prefix the token yourself (`Bearer ${accessToken}`) before passing it in, since the component sends whatever string you give it verbatim.
|
|
381
|
+
|
|
382
|
+
## Example App
|
|
383
|
+
|
|
384
|
+
The `example/` app is a full interactive demo, not just a form:
|
|
385
|
+
|
|
386
|
+
- **Overview** — the landing tab: the pitch, a live tracker for issue/archived/comment/webhook counts (visible from every tab, not just this one), a team picker and "paste a team UUID" fallback, a walkthrough of how the archive/trash reconciliation actually works, and a quick-start code sample.
|
|
387
|
+
- **Issues** — file an issue (with suggestion chips), reprioritize it, archive or restore it, and add comments, all reactively reflected the instant the action call returns — no waiting on the webhook.
|
|
388
|
+
- **Webhooks** — a live, expandable feed of every raw delivery to `/webhooks/linear`, across every team you've connected, so you can watch signature verification, deduplication, and the ground-truth re-fetch happen in real time.
|
|
389
|
+
- **History** — every issue and comment this component has ever recorded, newest first, across every team, with a one-click "file follow-up issue" action.
|
|
390
|
+
- A sidebar **Activity** console logging every action call this demo makes, with its result or error.
|
|
391
|
+
|
|
392
|
+
Run it from the repo root (not `example/`):
|
|
393
|
+
|
|
394
|
+
```sh
|
|
395
|
+
npm install --legacy-peer-deps
|
|
396
|
+
npx convex env set LINEAR_API_KEY lin_api_...
|
|
397
|
+
npx convex env set LINEAR_WEBHOOK_SECRET whsec_...
|
|
398
|
+
npm run dev
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
Then register a webhook on a scratch team pointed at `https://<your-dev-deployment>.convex.site/webhooks/linear` (see [Quick Start](#quick-start)) to see live deliveries land in the Webhooks tab.
|
|
402
|
+
|
|
403
|
+
## Testing
|
|
404
|
+
|
|
405
|
+
```sh
|
|
406
|
+
npm run test
|
|
407
|
+
npm run typecheck
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
Tests use [`convex-test`](https://www.npmjs.com/package/convex-test) and cover `recordIssue` upsert behavior (including the `trashed` flag being carried through re-records), `listIssuesByTeam` scoping by team, `removeIssue` deletion, `setIssueArchived` archiving/restoring without deleting the row, `recordComment` upsert behavior, and webhook idempotency via `checkAndRecordEvent`.
|
|
411
|
+
|
|
412
|
+
## Limitations
|
|
413
|
+
|
|
414
|
+
- Only `Issue` and `Comment` webhook resource types are processed; `Project`, `Cycle`, `IssueLabel`, and other resource types are out of scope for this component.
|
|
415
|
+
- All mutations (`createIssue`, `updateIssue`, `createComment`, `archiveIssue`, `unarchiveIssue`) go through Linear's GraphQL API directly — this component does not wrap every GraphQL mutation Linear exposes (e.g. issue relations, sub-issues, project updates).
|
|
416
|
+
- The component does not manage webhook registration for you — you create the webhook once in Linear's UI or via the GraphQL API yourself.
|
|
417
|
+
- Rate limits are Linear's own (complexity-based, roughly 1,500 points/hour for API keys) — this component does not implement its own rate limiting or backoff.
|
|
418
|
+
- Every `Issue` webhook delivery makes one extra outbound call to Linear's GraphQL API (the re-fetch described in [Webhook Events](#webhook-events)) before writing anything to Convex — a deliberate tradeoff for correctness given `action` alone is unreliable, but worth knowing if you're watching Linear API usage closely. If that re-fetch throws for a reason other than "not found" (a transient network error, a rate limit), the webhook request fails; because the delivery was already marked processed for idempotency purposes before the re-fetch ran, a Linear-side retry of that same delivery will be treated as a duplicate and skipped rather than retried — in practice this means a very unlucky transient failure can leave one issue's mirror stale until its next change.
|
|
419
|
+
|
|
420
|
+
## Troubleshooting
|
|
421
|
+
|
|
422
|
+
**Webhook returns 401** — the signature didn't match. Double check `LINEAR_WEBHOOK_SECRET` matches exactly what Linear showed you when the webhook was created (this secret is only shown once).
|
|
423
|
+
|
|
424
|
+
**Webhook returns 400 "Stale webhook timestamp"** — your Convex deployment's clock and Linear's disagree by more than 60 seconds, or the request took unusually long to arrive. This is intentionally strict to guard against replay; if you're testing with a manually-crafted request, make sure `Linear-Timestamp` is the current Unix time in milliseconds.
|
|
425
|
+
|
|
426
|
+
**Issues never appear in queries** — confirm the webhook's delivery log in Linear shows a `200` response, and that the webhook is subscribed to the **Issues** and **Comments** resource types specifically.
|
|
427
|
+
|
|
428
|
+
**`updateIssue` doesn't seem to change the state** — `stateId` must be the UUID of a workflow state that belongs to the issue's own team; state UUIDs are not shared across teams even when the state names look the same (e.g. every team has its own "In Progress").
|
|
429
|
+
|
|
430
|
+
## Contributing
|
|
431
|
+
|
|
432
|
+
See [CONTRIBUTING.md](./CONTRIBUTING.md).
|
|
433
|
+
|
|
434
|
+
## Changelog
|
|
435
|
+
|
|
436
|
+
See [CHANGELOG.md](./CHANGELOG.md).
|
|
437
|
+
|
|
438
|
+
<!-- END: Include on https://convex.dev/components -->
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=_ignore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_ignore.d.ts","sourceRoot":"","sources":["../../../src/client/_generated/_ignore.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_ignore.js","sourceRoot":"","sources":["../../../src/client/_generated/_ignore.ts"],"names":[],"mappings":";AAAA,kEAAkE"}
|