@lornatang/dsh-atlassian 0.1.11 → 0.1.12

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/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.12 - 2026-11-18
4
+
5
+ - Re-arm the OAuth callback listener when authorization starts, so a callback port that becomes available after a failed bind no longer leaves the published redirect URI pointing at port 0.
6
+ - Publish the authorization URL only while a callback wait is armed, preventing a browser flow that would land on an unbound listener and fail with HTTP 400.
7
+ - Reset the observed token snapshot after a successful credential invalidation, so the built-in re-authorization no longer fails with a stale-credentials conflict.
8
+ - Hold the shared session lease until an in-flight token exchange settles instead of releasing it from the client error hook, avoiding a spurious invalid-session-lock failure.
9
+ - Validate the site label reported by the server before caching it.
10
+ - Reject malformed percent-encoded issue keys with a 400 response and bound request-body reads with a deadline.
11
+ - Reflect saved connection settings in the live configuration instead of only in the planner draft.
12
+ - Include a GitHub release archive; this release is also published to npm.
13
+
3
14
  ## 0.1.11 - 2026-11-17
4
15
 
5
16
  - Invalidate the cached Jira site whenever the connection is replaced and deduplicate concurrent site lookups, so a reconnect can never serve data from the previous site.
package/README.md CHANGED
@@ -34,7 +34,7 @@ dsh plugin --profile <name> add @lornatang/dsh-atlassian
34
34
  dsh plugin --profile <name> remove @lornatang/dsh-atlassian
35
35
  ```
36
36
 
37
- The same release is also attached as an archive on GitHub: `dsh plugin --profile <name> add https://github.com/Lornatang/dsh-atlassian/releases/download/v0.1.11/lornatang-dsh-atlassian-0.1.11.tgz`.
37
+ The same release is also attached as an archive on GitHub: `dsh plugin --profile <name> add https://github.com/Lornatang/dsh-atlassian/releases/download/v0.1.12/lornatang-dsh-atlassian-0.1.12.tgz`.
38
38
 
39
39
  `add` composes the layer into the profile: the profile's `cordis.patch.yml` gains an insert entry with row id `atlassian`, package `@lornatang/dsh-atlassian`, and the five values the shipped patch carries — `mode: cloud`, `serverName: atlassian`, `url: https://mcp.atlassian.com/v1/mcp`, `redirectPort: 3334` and `autoOpenBrowser: true`. The manifest declares `dsh.bundle.patch: ./cordis.patch.yml`, which is the declaration the reconcile step reads; `remove` deletes the entry again. Restart DSH after either command, because the profile composes its rows and its client half only at startup, then open Settings → Atlassian. Releases before 0.1.5 published this package as `@lornatang/dsh-atlassian-bridge`; add the scoped name, remove the old package from the same profile and restart once — the row, its settings and the stored credentials survive.
40
40
 
package/README.zh.md CHANGED
@@ -34,7 +34,7 @@ dsh plugin --profile <name> add @lornatang/dsh-atlassian
34
34
  dsh plugin --profile <name> remove @lornatang/dsh-atlassian
35
35
  ```
36
36
 
37
- 也可以从 GitHub release 附带的压缩包安装同一版本:`dsh plugin --profile <name> add https://github.com/Lornatang/dsh-atlassian/releases/download/v0.1.11/lornatang-dsh-atlassian-0.1.11.tgz`。
37
+ 也可以从 GitHub release 附带的压缩包安装同一版本:`dsh plugin --profile <name> add https://github.com/Lornatang/dsh-atlassian/releases/download/v0.1.12/lornatang-dsh-atlassian-0.1.12.tgz`。
38
38
 
39
39
  `add` 会把本层组合进 profile:profile 的 `cordis.patch.yml` 会增加一条 insert 记录,行 id 为 `atlassian`,包名为 `@lornatang/dsh-atlassian`,并带上随包提供的补丁中的五个值——`mode: cloud`、`serverName: atlassian`、`url: https://mcp.atlassian.com/v1/mcp`、`redirectPort: 3334` 与 `autoOpenBrowser: true`。包的 manifest 声明了 `dsh.bundle.patch: ./cordis.patch.yml`,reconcile 步骤读取的正是这条声明;`remove` 会再次删除该记录。两条命令执行后都要重启 DSH,因为 profile 只在启动时组合自己的行与客户端部分,随后打开 Settings → Atlassian。0.1.5 之前的版本以 `@lornatang/dsh-atlassian-bridge` 发布;添加带作用域的新名称、从同一 profile 删除旧包、重启一次即可——行、其设置与已保存的凭据都会保留。
40
40
 
package/lib/bridge.js CHANGED
@@ -56,10 +56,13 @@ export class AtlassianBridge {
56
56
  #flight;
57
57
  #refreshes = new Set();
58
58
  #waiters = new Set();
59
+ #waiting = false;
60
+ #allowLoopbackHttp;
59
61
  constructor(host, options) {
60
62
  this.#host = host;
61
63
  this.#options = options;
62
64
  const network = createCloudFetch(new URL(options.url));
65
+ this.#allowLoopbackHttp = network.allowLoopbackHttp;
63
66
  const active = () => {
64
67
  const operation = this.#operation.getStore();
65
68
  return !this.#disposed && (!operation || (operation.generation === this.#generation && !operation.signal.aborted));
@@ -129,10 +132,12 @@ export class AtlassianBridge {
129
132
  operation.releaseRefresh = undefined;
130
133
  };
131
134
  this.#flight = { owner: operation, done };
135
+ operation.exchangePending = true;
132
136
  operation.lease = lease;
133
137
  operation.releaseRefresh = release;
134
138
  signal.addEventListener('abort', release, { once: true });
135
139
  if (signal.aborted) {
140
+ operation.exchangePending = false;
136
141
  pending = false;
137
142
  release();
138
143
  throw new Error('atlassian: connection cancelled');
@@ -161,6 +166,7 @@ export class AtlassianBridge {
161
166
  throw error;
162
167
  }
163
168
  finally {
169
+ operation.exchangePending = false;
164
170
  pending = false;
165
171
  if (requested)
166
172
  release();
@@ -197,6 +203,13 @@ export class AtlassianBridge {
197
203
  lease: () => this.#operation.getStore()?.lease,
198
204
  observedTokens: () => this.#operation.getStore()?.observedTokens,
199
205
  signal: () => this.#operation.getStore()?.signal,
206
+ resetObservation: () => {
207
+ const operation = this.#operation.getStore();
208
+ if (!operation)
209
+ return;
210
+ operation.observedTokens = undefined;
211
+ operation.refreshExpected = undefined;
212
+ },
200
213
  });
201
214
  }
202
215
  #newOperation() { return { generation: this.#generation, signal: this.#controller.signal }; }
@@ -234,7 +247,9 @@ export class AtlassianBridge {
234
247
  mismatch = true;
235
248
  }
236
249
  }
237
- return { status: this.#status, authorizationUrl: this.#url, site, siteMismatch: mismatch, toolCount: this.#tools.size, error: this.#error };
250
+ // Only publish a URL while a callback wait is armed; following it otherwise
251
+ // would reach an unbound callback listener and fail with an HTTP 400.
252
+ return { status: this.#status, authorizationUrl: this.#waiting ? this.#url : undefined, site, siteMismatch: mismatch, toolCount: this.#tools.size, error: this.#error };
238
253
  }
239
254
  rawNames() { return [...this.#tools.values()].map((value) => value.raw); }
240
255
  rawNameMatching(pattern) { return this.rawNames().find((name) => pattern.test(name)); }
@@ -276,6 +291,8 @@ export class AtlassianBridge {
276
291
  await this.#boot;
277
292
  if (this.#disposed || this.#status === 'ready')
278
293
  return this.snapshot();
294
+ if (!this.#callback.listening)
295
+ await this.#callback.listen(this.#options.redirectPort);
279
296
  if (this.#status === 'authorizing' && this.#url) {
280
297
  if (this.#options.autoOpenBrowser)
281
298
  await openInBrowser(this.#url);
@@ -311,8 +328,11 @@ export class AtlassianBridge {
311
328
  check();
312
329
  this.#setStatus('connecting');
313
330
  this.#error = undefined;
314
- const client = new Client({ name: 'dsh-atlassian', version: '0.1.11' });
315
- client.onerror = () => { this.#operation.getStore()?.releaseRefresh?.(); };
331
+ const client = new Client({ name: 'dsh-atlassian', version: '0.1.12' });
332
+ // Releasing the session lease here would race the SDK's saveTokens; an
333
+ // exchange that is still in flight is released by its own finally block.
334
+ client.onerror = () => { const operation = this.#operation.getStore(); if (operation?.exchangePending)
335
+ operation.releaseRefresh?.(); };
316
336
  const transport = new StreamableHTTPClientTransport(new URL(this.#options.url), { authProvider: this.#provider, fetch: this.#fetch });
317
337
  const send = transport.send.bind(transport);
318
338
  transport.send = (message, options) => {
@@ -346,14 +366,20 @@ export class AtlassianBridge {
346
366
  throw error;
347
367
  const state = this.#url ? new URL(this.#url).searchParams.get('state') ?? undefined : undefined;
348
368
  const waiting = this.#callback.waitForCode(this.#options.authorizationTimeoutMs, state);
369
+ this.#waiting = true;
349
370
  this.#setStatus('authorizing');
350
371
  if (open && this.#url && this.#options.autoOpenBrowser)
351
372
  void openInBrowser(this.#url);
352
- const callback = await waiting;
353
- check();
354
- await this.#operation.run(this.#newOperation(), () => auth(this.#provider, { serverUrl: this.#options.url, authorizationCode: callback.code, fetchFn: this.#fetch }));
355
- check();
356
- await this.#options.store.clearCredentialsIf(() => !this.#disposed && generation === this.#generation, undefined, undefined, this.#controller.signal, false, 'codeVerifier');
373
+ try {
374
+ const callback = await waiting;
375
+ check();
376
+ await this.#operation.run(this.#newOperation(), () => auth(this.#provider, { serverUrl: this.#options.url, authorizationCode: callback.code, fetchFn: this.#fetch }));
377
+ check();
378
+ await this.#options.store.clearCredentialsIf(() => !this.#disposed && generation === this.#generation, undefined, undefined, this.#controller.signal, false, 'codeVerifier');
379
+ }
380
+ finally {
381
+ this.#waiting = false;
382
+ }
357
383
  continue;
358
384
  }
359
385
  this.#client = client;
@@ -425,7 +451,9 @@ export class AtlassianBridge {
425
451
  const items = JSON.parse(display(result.content));
426
452
  const first = Array.isArray(items) ? items[0] : items;
427
453
  if (first && typeof first === 'object' && typeof first['url'] === 'string') {
428
- await this.#options.store.patch({ site: new URL(first['url']).host }, () => !this.#disposed && generation === this.#generation && !signal.aborted, undefined, undefined, signal);
454
+ const reported = new URL(first['url']);
455
+ secureUrl(reported, this.#allowLoopbackHttp);
456
+ await this.#options.store.patch({ site: reported.host }, () => !this.#disposed && generation === this.#generation && !signal.aborted, undefined, undefined, signal);
429
457
  }
430
458
  }
431
459
  catch { /* The connection can work without a site label. */ }
package/lib/config.js CHANGED
@@ -44,12 +44,12 @@ export function configureEndpoints(current, input) {
44
44
  }
45
45
  export const Config = z.object({
46
46
  mode: z.union(['cloud', 'server']).default('cloud'),
47
- serverName: z.string().default('atlassian'),
47
+ serverName: z.string().default('atlassian').pattern(/^[A-Za-z0-9_-]{1,64}$/),
48
48
  url: z.string().default(DEFAULT_CLOUD_URL),
49
49
  redirectPort: z.number().step(1).min(0).max(65535).default(3334),
50
- toolCallTimeoutMs: z.number().step(1).min(1).default(60000),
50
+ toolCallTimeoutMs: z.number().step(1).min(1).max(2_147_483_647).default(60000),
51
51
  expectedSite: z.string().default(''),
52
- authorizationTimeoutMs: z.number().step(1).min(1000).default(300000),
52
+ authorizationTimeoutMs: z.number().step(1).min(1000).max(2_147_483_647).default(300000),
53
53
  autoOpenBrowser: z.boolean().default(true),
54
54
  server: z.object({
55
55
  jiraUrl: z.string().default(''),
package/lib/index.js CHANGED
@@ -22,7 +22,7 @@ export function apply(ctx, config) {
22
22
  const connection = {
23
23
  snapshot: () => ({ ...config.server }),
24
24
  update: async (input) => {
25
- const next = configureEndpoints(config, input);
25
+ const next = Object.assign(config, configureEndpoints(config, input));
26
26
  const editor = scope.get('configEditor');
27
27
  const entry = editor?.entries().find((candidate) => candidate.options.id === 'atlassian');
28
28
  if (!editor || !entry)
package/lib/oauth.js CHANGED
@@ -104,9 +104,16 @@ export class CallbackServer {
104
104
  #port = 0;
105
105
  #pending;
106
106
  get redirectUri() { return `http://127.0.0.1:${this.#port}/callback`; }
107
+ get listening() { return this.#server?.listening === true; }
107
108
  async listen(preferredPort) {
108
- if (this.#server)
109
+ if (this.#server?.listening)
109
110
  return this.#port;
111
+ const stale = this.#server;
112
+ if (stale) {
113
+ this.#server = undefined;
114
+ this.cancelWait();
115
+ await new Promise((resolve) => { stale.close(() => resolve()); });
116
+ }
110
117
  const server = createServer((req, res) => {
111
118
  let url;
112
119
  try {
@@ -151,7 +158,10 @@ export class CallbackServer {
151
158
  this.#port = await bind(preferredPort);
152
159
  }
153
160
  catch (error) {
154
- if (error.code !== 'EADDRINUSE' || preferredPort === 0)
161
+ const code = error.code;
162
+ // A privileged or unavailable port must not leave redirectUri pointing at
163
+ // port 0; retry any bind failure that a dynamic port can avoid.
164
+ if (preferredPort === 0 || (code !== 'EADDRINUSE' && code !== 'EACCES' && code !== 'EADDRNOTAVAIL'))
155
165
  throw error;
156
166
  this.#port = await bind(0);
157
167
  }
@@ -215,6 +225,7 @@ export class AtlassianOAuthProvider {
215
225
  #lease;
216
226
  #observedTokens;
217
227
  #signal;
228
+ #resetObservation;
218
229
  constructor(options) {
219
230
  this.#store = options.store;
220
231
  this.#redirect = options.redirectUri;
@@ -227,6 +238,7 @@ export class AtlassianOAuthProvider {
227
238
  this.#lease = options.lease ?? (() => undefined);
228
239
  this.#observedTokens = options.observedTokens ?? (() => undefined);
229
240
  this.#signal = options.signal ?? (() => undefined);
241
+ this.#resetObservation = options.resetObservation ?? (() => undefined);
230
242
  }
231
243
  #check() { if (!this.#active())
232
244
  throw new Error('atlassian: connection cancelled'); }
@@ -276,14 +288,20 @@ export class AtlassianOAuthProvider {
276
288
  async invalidateCredentials(scope) {
277
289
  try {
278
290
  const expected = this.#refreshExpected() ?? this.#observedTokens();
291
+ let cleared = false;
279
292
  if (scope === 'all')
280
- await this.#store.clearCredentialsIf(this.#active, expected, this.#lease(), this.#signal(), true, 'tokens', 'clientInformation', 'codeVerifier');
293
+ cleared = await this.#store.clearCredentialsIf(this.#active, expected, this.#lease(), this.#signal(), true, 'tokens', 'clientInformation', 'codeVerifier');
281
294
  else if (scope === 'client')
282
- await this.#store.clearCredentialsIf(this.#active, expected, this.#lease(), this.#signal(), true, 'clientInformation');
295
+ cleared = await this.#store.clearCredentialsIf(this.#active, expected, this.#lease(), this.#signal(), true, 'clientInformation');
283
296
  else if (scope === 'tokens')
284
- await this.#store.clearCredentialsIf(this.#active, expected, this.#lease(), this.#signal(), true, 'tokens');
297
+ cleared = await this.#store.clearCredentialsIf(this.#active, expected, this.#lease(), this.#signal(), true, 'tokens');
285
298
  else if (scope === 'verifier')
286
- await this.#store.clearCredentialsIf(this.#active, expected, this.#lease(), this.#signal(), true, 'codeVerifier');
299
+ cleared = await this.#store.clearCredentialsIf(this.#active, expected, this.#lease(), this.#signal(), true, 'codeVerifier');
300
+ // Only a clear this operation actually performed invalidates its observation.
301
+ // If another process removed or replaced the session, the stale observation
302
+ // must keep refusing credential writes.
303
+ if (cleared && (scope === 'all' || scope === 'tokens'))
304
+ this.#resetObservation();
287
305
  }
288
306
  finally {
289
307
  this.#authFinished();
package/lib/routes.js CHANGED
@@ -70,6 +70,25 @@ export function registerRoutes(web, bridge, board, options, fence, connection) {
70
70
  const action = url.pathname.slice(ROUTE_PREFIX.length).replace(/^\//, '');
71
71
  const method = req.method ?? 'GET';
72
72
  try {
73
+ if (!fence) {
74
+ respond(res, 503, { ok: false, error: 'DSH connection service is unavailable' });
75
+ return;
76
+ }
77
+ const rejection = fence.requestRejection(req);
78
+ if (rejection !== undefined) {
79
+ res.writeHead(rejection).end();
80
+ return;
81
+ }
82
+ let url;
83
+ try {
84
+ url = new URL(req.url ?? '/', 'http://localhost');
85
+ }
86
+ catch {
87
+ respond(res, 400, { ok: false, error: 'invalid request target' });
88
+ return;
89
+ }
90
+ const action = url.pathname.slice(ROUTE_PREFIX.length).replace(/^\//, '');
91
+ const method = req.method ?? 'GET';
73
92
  if (method === 'GET' && action === 'status') {
74
93
  respond(res, 200, { ...bridge.snapshot(), ok: true, board: { jql: options.jql, limit: options.limit, promptTemplate: options.promptTemplate }, ...(connection ? { configuration: connection.snapshot() } : {}) });
75
94
  return;
@@ -77,9 +77,9 @@ export class ServerBridge {
77
77
  },
78
78
  };
79
79
  }
80
+ epoch() { return this.#generation; }
80
81
  rawNames() { return [...this.#operations.keys()]; }
81
82
  rawNameMatching(pattern) { return this.rawNames().find((name) => pattern.test(name)); }
82
- epoch() { return this.#generation; }
83
83
  async start() {
84
84
  if (this.#starting)
85
85
  return this.#starting;
package/lib/store.js CHANGED
@@ -257,7 +257,13 @@ export class SessionStore {
257
257
  this.#value = next;
258
258
  }, lease, signal);
259
259
  }
260
+ /**
261
+ * Returns whether the guard matched and the credentials were actually cleared:
262
+ * a stale observation must keep refusing writes when another process removed
263
+ * the session first.
264
+ */
260
265
  async clearCredentialsIf(active, expected, lease, signal, guard, ...fields) {
266
+ let cleared = false;
261
267
  await this.#withLease(async () => {
262
268
  if (!active())
263
269
  throw new Error('atlassian: connection cancelled');
@@ -269,7 +275,9 @@ export class SessionStore {
269
275
  delete next[field];
270
276
  await this.#flush(next);
271
277
  this.#value = next;
278
+ cleared = true;
272
279
  }, lease, signal);
280
+ return cleared;
273
281
  }
274
282
  async clear(...fields) {
275
283
  await this.#withLease(async () => {
@@ -22,6 +22,7 @@ export declare function createCloudFetch(serverUrl: URL): {
22
22
  export declare class CallbackServer {
23
23
  #private;
24
24
  get redirectUri(): string;
25
+ get listening(): boolean;
25
26
  listen(preferredPort: number): Promise<number>;
26
27
  waitForCode(timeoutMs: number, state: string | undefined, signal?: AbortSignal): Promise<AuthorizationCallback>;
27
28
  cancelWait(): void;
@@ -42,6 +43,7 @@ export declare class AtlassianOAuthProvider implements OAuthClientProvider {
42
43
  lease?: () => SessionLease | undefined;
43
44
  observedTokens?: () => OAuthTokens | undefined;
44
45
  signal?: () => AbortSignal | undefined;
46
+ resetObservation?: () => void;
45
47
  });
46
48
  get redirectUrl(): string;
47
49
  get clientMetadata(): OAuthClientMetadata;
@@ -12,9 +12,9 @@ export declare class ServerBridge {
12
12
  timeoutMs: number;
13
13
  });
14
14
  snapshot(): BridgeSnapshot;
15
+ epoch(): number;
15
16
  rawNames(): readonly string[];
16
17
  rawNameMatching(pattern: RegExp): string | undefined;
17
- epoch(): number;
18
18
  start(): Promise<void>;
19
19
  authorize(input?: Args): Promise<BridgeSnapshot>;
20
20
  disconnect(): Promise<BridgeSnapshot>;
@@ -41,7 +41,12 @@ export declare class SessionStore {
41
41
  /** Re-register only when a new interactive flow needs a different callback. */
42
42
  rebindRedirect(actual: string, expected: OAuthTokens | undefined, active: () => boolean, lease?: SessionLease, signal?: AbortSignal): Promise<void>;
43
43
  saveTokens(tokens: OAuthTokens, active: () => boolean, expected?: OAuthTokens, lease?: SessionLease, signal?: AbortSignal, guard?: boolean): Promise<void>;
44
- clearCredentialsIf(active: () => boolean, expected: OAuthTokens | undefined, lease: SessionLease | undefined, signal: AbortSignal | undefined, guard: boolean, ...fields: readonly (keyof StoredSession)[]): Promise<void>;
44
+ /**
45
+ * Returns whether the guard matched and the credentials were actually cleared:
46
+ * a stale observation must keep refusing writes when another process removed
47
+ * the session first.
48
+ */
49
+ clearCredentialsIf(active: () => boolean, expected: OAuthTokens | undefined, lease: SessionLease | undefined, signal: AbortSignal | undefined, guard: boolean, ...fields: readonly (keyof StoredSession)[]): Promise<boolean>;
45
50
  clear(...fields: readonly (keyof StoredSession)[]): Promise<void>;
46
51
  destroy(): Promise<void>;
47
52
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lornatang/dsh-atlassian",
3
- "version": "0.1.11",
3
+ "version": "0.1.12",
4
4
  "description": "Connect Atlassian Cloud or self-hosted Jira and Confluence to DeepSeek Harness with tools and a Jira board.",
5
5
  "keywords": [
6
6
  "deepseek-harness",
@@ -78,7 +78,7 @@
78
78
  "@deepseek-ai/dsh-llm": "0.2.2-rc.2",
79
79
  "@deepseek-ai/dsh-tools": "0.2.2-rc.2",
80
80
  "@types/node": "^22.18.0",
81
- "@types/react": "^18.3.31",
81
+ "@types/react": "^19.3.0",
82
82
  "typescript": "^5.9.0"
83
83
  },
84
84
  "author": "Lornatang",