patchrelay 0.10.1 → 0.10.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/build-info.json +3 -3
- package/dist/cli/commands/connect.js +30 -4
- package/dist/cli/index.js +12 -1
- package/dist/cli/output.js +8 -1
- package/dist/db/linear-installation-store.js +9 -0
- package/dist/http.js +1 -1
- package/dist/linear-oauth-service.js +24 -4
- package/dist/service.js +2 -2
- package/package.json +1 -1
package/dist/build-info.json
CHANGED
|
@@ -18,11 +18,37 @@ export async function handleConnectCommand(params) {
|
|
|
18
18
|
export async function handleInstallationsCommand(params) {
|
|
19
19
|
const result = await params.data.listInstallations();
|
|
20
20
|
if (params.json) {
|
|
21
|
-
writeOutput(params.stdout, formatJson(
|
|
21
|
+
writeOutput(params.stdout, formatJson({
|
|
22
|
+
...result,
|
|
23
|
+
installations: result.installations.map((item) => ({
|
|
24
|
+
...item,
|
|
25
|
+
projects: item.linkedProjects.map((id) => {
|
|
26
|
+
const p = params.config.projects.find((proj) => proj.id === id);
|
|
27
|
+
return p ? { id: p.id, repoPath: p.repoPath, issueKeyPrefixes: p.issueKeyPrefixes, linearTeamIds: p.linearTeamIds } : { id };
|
|
28
|
+
}),
|
|
29
|
+
})),
|
|
30
|
+
}));
|
|
22
31
|
return 0;
|
|
23
32
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
33
|
+
if (result.installations.length === 0) {
|
|
34
|
+
writeOutput(params.stdout, "No installations found.\n");
|
|
35
|
+
return 0;
|
|
36
|
+
}
|
|
37
|
+
const lines = [];
|
|
38
|
+
for (const item of result.installations) {
|
|
39
|
+
const label = item.installation.workspaceName ?? item.installation.actorName ?? "-";
|
|
40
|
+
lines.push(`${item.installation.id} ${label} projects=${item.linkedProjects.join(",") || "-"}`);
|
|
41
|
+
for (const projectId of item.linkedProjects) {
|
|
42
|
+
const p = params.config.projects.find((proj) => proj.id === projectId);
|
|
43
|
+
if (!p)
|
|
44
|
+
continue;
|
|
45
|
+
const routing = [
|
|
46
|
+
...(p.issueKeyPrefixes.length > 0 ? [`prefixes=${p.issueKeyPrefixes.join(",")}`] : []),
|
|
47
|
+
...(p.linearTeamIds.length > 0 ? [`teams=${p.linearTeamIds.join(",")}`] : []),
|
|
48
|
+
].join(" ") || "no routing";
|
|
49
|
+
lines.push(` ${projectId} ${p.repoPath} ${routing}`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
writeOutput(params.stdout, `${lines.join("\n")}\n`);
|
|
27
53
|
return 0;
|
|
28
54
|
}
|
package/dist/cli/index.js
CHANGED
|
@@ -212,7 +212,17 @@ export async function runCli(argv, options) {
|
|
|
212
212
|
if (command === "doctor") {
|
|
213
213
|
const { runPreflight } = await import("../preflight.js");
|
|
214
214
|
const report = await runPreflight(config);
|
|
215
|
-
|
|
215
|
+
const cliVersion = getBuildInfo().version;
|
|
216
|
+
let serviceVersion;
|
|
217
|
+
try {
|
|
218
|
+
const healthUrl = `http://${config.server.bind}:${config.server.port}${config.server.healthPath}`;
|
|
219
|
+
const res = await fetch(healthUrl, { signal: AbortSignal.timeout(2000) });
|
|
220
|
+
const body = await res.json();
|
|
221
|
+
serviceVersion = body.version ?? undefined;
|
|
222
|
+
}
|
|
223
|
+
catch { /* service not reachable */ }
|
|
224
|
+
const doctorReport = { ...report, cliVersion, serviceVersion };
|
|
225
|
+
writeOutput(stdout, json ? formatJson(doctorReport) : formatDoctor(doctorReport, cliVersion, serviceVersion));
|
|
216
226
|
return report.ok ? 0 : 1;
|
|
217
227
|
}
|
|
218
228
|
if (command === "inspect") {
|
|
@@ -288,6 +298,7 @@ export async function runCli(argv, options) {
|
|
|
288
298
|
json,
|
|
289
299
|
stdout,
|
|
290
300
|
data: operatorData,
|
|
301
|
+
config,
|
|
291
302
|
});
|
|
292
303
|
}
|
|
293
304
|
if (command === "feed") {
|
package/dist/cli/output.js
CHANGED
|
@@ -5,8 +5,15 @@ export function writeOutput(stream, text) {
|
|
|
5
5
|
export function writeUsageError(stream, error) {
|
|
6
6
|
writeOutput(stream, `${helpTextFor(error.helpTopic)}\n\nError: ${error.message}\n`);
|
|
7
7
|
}
|
|
8
|
-
export function formatDoctor(report) {
|
|
8
|
+
export function formatDoctor(report, cliVersion, serviceVersion) {
|
|
9
9
|
const lines = ["PatchRelay doctor", ""];
|
|
10
|
+
if (cliVersion) {
|
|
11
|
+
const versionLine = serviceVersion
|
|
12
|
+
? (cliVersion === serviceVersion ? `cli=${cliVersion} service=${serviceVersion}` : `cli=${cliVersion} service=${serviceVersion} (mismatch!)`)
|
|
13
|
+
: `cli=${cliVersion} service=not reachable`;
|
|
14
|
+
lines.push(versionLine);
|
|
15
|
+
lines.push("");
|
|
16
|
+
}
|
|
10
17
|
for (const check of report.checks) {
|
|
11
18
|
const marker = check.status === "pass" ? "PASS" : check.status === "warn" ? "WARN" : "FAIL";
|
|
12
19
|
lines.push(`${marker} [${check.scope}] ${check.message}`);
|
|
@@ -58,6 +58,15 @@ export class LinearInstallationStore {
|
|
|
58
58
|
.run(params.accessTokenCiphertext, params.refreshTokenCiphertext ?? null, params.scopesJson ?? null, params.tokenType ?? null, params.expiresAt ?? null, isoNow(), id);
|
|
59
59
|
return this.getLinearInstallation(id);
|
|
60
60
|
}
|
|
61
|
+
updateLinearInstallationIdentity(id, params) {
|
|
62
|
+
this.connection
|
|
63
|
+
.prepare(`UPDATE linear_installations
|
|
64
|
+
SET workspace_name = COALESCE(?, workspace_name),
|
|
65
|
+
workspace_key = COALESCE(?, workspace_key),
|
|
66
|
+
updated_at = ?
|
|
67
|
+
WHERE id = ?`)
|
|
68
|
+
.run(params.workspaceName ?? null, params.workspaceKey ?? null, isoNow(), id);
|
|
69
|
+
}
|
|
61
70
|
getLinearInstallation(id) {
|
|
62
71
|
const row = this.connection
|
|
63
72
|
.prepare("SELECT * FROM linear_installations WHERE id = ?")
|
package/dist/http.js
CHANGED
|
@@ -332,7 +332,7 @@ export async function buildHttpServer(config, service, logger) {
|
|
|
332
332
|
});
|
|
333
333
|
app.get("/api/oauth/linear/start", async (request, reply) => {
|
|
334
334
|
const projectId = getQueryParam(request, "projectId");
|
|
335
|
-
const result = service.createLinearOAuthStart(projectId ? { projectId } : undefined);
|
|
335
|
+
const result = await service.createLinearOAuthStart(projectId ? { projectId } : undefined);
|
|
336
336
|
return reply.send({ ok: true, ...result });
|
|
337
337
|
});
|
|
338
338
|
app.get("/api/oauth/linear/state/:state", async (request, reply) => {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { createLinearOAuthUrl, createOAuthStateToken, installLinearOAuthCode } from "./linear-oauth.js";
|
|
1
|
+
import { createLinearOAuthUrl, createOAuthStateToken, fetchLinearViewerIdentity, installLinearOAuthCode } from "./linear-oauth.js";
|
|
2
|
+
import { decryptSecret } from "./token-crypto.js";
|
|
2
3
|
const LINEAR_OAUTH_STATE_TTL_MS = 15 * 60 * 1000;
|
|
3
4
|
function oauthStateExpired(createdAt) {
|
|
4
5
|
const createdAtMs = Date.parse(createdAt);
|
|
@@ -13,7 +14,7 @@ export class LinearOAuthService {
|
|
|
13
14
|
this.stores = stores;
|
|
14
15
|
this.logger = logger;
|
|
15
16
|
}
|
|
16
|
-
createStart(params) {
|
|
17
|
+
async createStart(params) {
|
|
17
18
|
if (params?.projectId && !this.config.projects.some((project) => project.id === params.projectId)) {
|
|
18
19
|
throw new Error(`Unknown project: ${params.projectId}`);
|
|
19
20
|
}
|
|
@@ -22,11 +23,13 @@ export class LinearOAuthService {
|
|
|
22
23
|
if (existingLink) {
|
|
23
24
|
const installation = this.stores.linearInstallations.getLinearInstallation(existingLink.installationId);
|
|
24
25
|
if (installation) {
|
|
26
|
+
await this.refreshInstallationIdentity(installation);
|
|
27
|
+
const updated = this.stores.linearInstallations.getLinearInstallation(installation.id) ?? installation;
|
|
25
28
|
return {
|
|
26
29
|
completed: true,
|
|
27
30
|
reusedExisting: true,
|
|
28
31
|
projectId: params.projectId,
|
|
29
|
-
installation: this.getInstallationSummary(
|
|
32
|
+
installation: this.getInstallationSummary(updated),
|
|
30
33
|
};
|
|
31
34
|
}
|
|
32
35
|
}
|
|
@@ -35,11 +38,13 @@ export class LinearOAuthService {
|
|
|
35
38
|
const installation = installations[0];
|
|
36
39
|
if (installation) {
|
|
37
40
|
this.stores.linearInstallations.linkProjectInstallation(params.projectId, installation.id);
|
|
41
|
+
await this.refreshInstallationIdentity(installation);
|
|
42
|
+
const updated = this.stores.linearInstallations.getLinearInstallation(installation.id) ?? installation;
|
|
38
43
|
return {
|
|
39
44
|
completed: true,
|
|
40
45
|
reusedExisting: true,
|
|
41
46
|
projectId: params.projectId,
|
|
42
|
-
installation: this.getInstallationSummary(
|
|
47
|
+
installation: this.getInstallationSummary(updated),
|
|
43
48
|
};
|
|
44
49
|
}
|
|
45
50
|
}
|
|
@@ -118,6 +123,21 @@ export class LinearOAuthService {
|
|
|
118
123
|
linkedProjects: links.filter((link) => link.installationId === installation.id).map((link) => link.projectId),
|
|
119
124
|
}));
|
|
120
125
|
}
|
|
126
|
+
async refreshInstallationIdentity(installation) {
|
|
127
|
+
try {
|
|
128
|
+
const accessToken = decryptSecret(installation.accessTokenCiphertext, this.config.linear.tokenEncryptionKey);
|
|
129
|
+
const identity = await fetchLinearViewerIdentity(this.config.linear.graphqlUrl, accessToken, this.logger);
|
|
130
|
+
if (identity.workspaceName || identity.workspaceKey) {
|
|
131
|
+
this.stores.linearInstallations.updateLinearInstallationIdentity(installation.id, {
|
|
132
|
+
...(identity.workspaceName ? { workspaceName: identity.workspaceName } : {}),
|
|
133
|
+
...(identity.workspaceKey ? { workspaceKey: identity.workspaceKey } : {}),
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
this.logger.debug({ installationId: installation.id, error: error instanceof Error ? error.message : String(error) }, "Failed to refresh installation identity (non-blocking)");
|
|
139
|
+
}
|
|
140
|
+
}
|
|
121
141
|
getInstallationSummary(installation) {
|
|
122
142
|
return {
|
|
123
143
|
id: installation.id,
|
package/dist/service.js
CHANGED
|
@@ -48,8 +48,8 @@ export class PatchRelayService {
|
|
|
48
48
|
stop() {
|
|
49
49
|
this.runtime.stop();
|
|
50
50
|
}
|
|
51
|
-
createLinearOAuthStart(params) {
|
|
52
|
-
return this.oauthService.createStart(params);
|
|
51
|
+
async createLinearOAuthStart(params) {
|
|
52
|
+
return await this.oauthService.createStart(params);
|
|
53
53
|
}
|
|
54
54
|
async completeLinearOAuth(params) {
|
|
55
55
|
return await this.oauthService.complete(params);
|