@kaddo/cli 3.88.2 → 3.88.4

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 (3) hide show
  1. package/dist/core.js +52 -19
  2. package/dist/index.js +52 -19
  3. package/package.json +1 -1
package/dist/core.js CHANGED
@@ -10126,7 +10126,7 @@ function buildJql(filters) {
10126
10126
  if (filters?.updatedAfter) clauses.push(`updated >= ${escapeJql(filters.updatedAfter)}`);
10127
10127
  if (filters?.search) clauses.push(`(summary ~ ${escapeJql(filters.search)} OR description ~ ${escapeJql(filters.search)})`);
10128
10128
  if (filters?.providerQuery) clauses.push(`(${filters.providerQuery})`);
10129
- return clauses.join(" AND ") || "ORDER BY updated DESC";
10129
+ return clauses.join(" AND ");
10130
10130
  }
10131
10131
  function normalizeBaseUrl(raw) {
10132
10132
  let url = raw.trim();
@@ -10137,6 +10137,26 @@ function authHeader(email, token) {
10137
10137
  const encoded = typeof Buffer !== "undefined" ? Buffer.from(`${email}:${token}`).toString("base64") : btoa(`${email}:${token}`);
10138
10138
  return `Basic ${encoded}`;
10139
10139
  }
10140
+ async function handleJiraResponse(res) {
10141
+ if (res.status === 401) throw integrationError("INTEGRATION_UNAUTHORIZED");
10142
+ if (res.status === 403) throw integrationError("INTEGRATION_FORBIDDEN");
10143
+ if (res.status === 404) throw integrationError("INTEGRATION_NOT_FOUND");
10144
+ if (res.status === 410) throw integrationError("INTEGRATION_UNAVAILABLE", "Jira API endpoint deprecated (410 Gone).");
10145
+ if (res.status === 429) throw integrationError("INTEGRATION_RATE_LIMITED");
10146
+ if (res.status >= 500) throw integrationError("INTEGRATION_UNAVAILABLE");
10147
+ if (!res.ok) {
10148
+ let detail = "";
10149
+ try {
10150
+ const body = await res.json();
10151
+ const msgs = body.errorMessages?.filter(Boolean) ?? [];
10152
+ const fieldErrs = body.errors ? Object.entries(body.errors).map(([k, v]) => `${k}: ${v}`) : [];
10153
+ detail = [...msgs, ...fieldErrs].join("; ");
10154
+ } catch {
10155
+ }
10156
+ throw integrationError("INTEGRATION_PROVIDER_ERROR", detail || `Jira responded with status ${res.status}.`);
10157
+ }
10158
+ return await res.json();
10159
+ }
10140
10160
  async function jiraFetch(baseUrl, path4, auth, timeoutMs, params) {
10141
10161
  const url = new URL(path4, baseUrl + "/");
10142
10162
  if (params) for (const [k, v] of Object.entries(params)) url.searchParams.set(k, v);
@@ -10148,14 +10168,26 @@ async function jiraFetch(baseUrl, path4, auth, timeoutMs, params) {
10148
10168
  headers: { Authorization: auth, Accept: "application/json" },
10149
10169
  signal: controller.signal
10150
10170
  });
10151
- if (res.status === 401) throw integrationError("INTEGRATION_UNAUTHORIZED");
10152
- if (res.status === 403) throw integrationError("INTEGRATION_FORBIDDEN");
10153
- if (res.status === 404) throw integrationError("INTEGRATION_NOT_FOUND");
10154
- if (res.status === 410) throw integrationError("INTEGRATION_UNAVAILABLE", "Jira API endpoint deprecated (410 Gone).");
10155
- if (res.status === 429) throw integrationError("INTEGRATION_RATE_LIMITED");
10156
- if (res.status >= 500) throw integrationError("INTEGRATION_UNAVAILABLE");
10157
- if (!res.ok) throw integrationError("INTEGRATION_PROVIDER_ERROR", `Jira responded with status ${res.status}.`);
10158
- return await res.json();
10171
+ return await handleJiraResponse(res);
10172
+ } catch (err) {
10173
+ if (err instanceof Error && err.name === "AbortError") throw integrationError("INTEGRATION_TIMEOUT");
10174
+ throw normalizeProviderError(err);
10175
+ } finally {
10176
+ clearTimeout(timer);
10177
+ }
10178
+ }
10179
+ async function jiraPost(baseUrl, path4, auth, timeoutMs, body) {
10180
+ const url = new URL(path4, baseUrl + "/");
10181
+ const controller = new AbortController();
10182
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
10183
+ try {
10184
+ const res = await fetch(url.toString(), {
10185
+ method: "POST",
10186
+ headers: { Authorization: auth, Accept: "application/json", "Content-Type": "application/json" },
10187
+ body: JSON.stringify(body),
10188
+ signal: controller.signal
10189
+ });
10190
+ return await handleJiraResponse(res);
10159
10191
  } catch (err) {
10160
10192
  if (err instanceof Error && err.name === "AbortError") throw integrationError("INTEGRATION_TIMEOUT");
10161
10193
  throw normalizeProviderError(err);
@@ -10274,18 +10306,19 @@ function createJiraAdapter() {
10274
10306
  const auth = authHeader(email, apiToken);
10275
10307
  const jql = buildJql(request.filters);
10276
10308
  const pageSize = Math.min(Math.max(1, request.pageSize ?? DEFAULT_PAGE_SIZE), 100);
10277
- const startAt = request.cursor ? Math.max(0, Number.parseInt(request.cursor, 10) || 0) : 0;
10309
+ const nextPageToken = request.cursor || void 0;
10278
10310
  try {
10279
- const data = await jiraFetch(baseUrl, "/rest/api/3/search/jql", auth, request.context.timeoutMs, {
10280
- jql: jql.startsWith("ORDER BY") ? jql : jql + " ORDER BY updated DESC",
10281
- startAt: String(startAt),
10282
- maxResults: String(pageSize),
10283
- fields: SEARCH_FIELDS
10284
- });
10311
+ const fullJql = jql ? jql + " ORDER BY updated DESC" : "updated >= -30d ORDER BY updated DESC";
10312
+ const body = {
10313
+ jql: fullJql,
10314
+ maxResults: pageSize,
10315
+ fields: SEARCH_FIELDS.split(",")
10316
+ };
10317
+ if (nextPageToken) body.nextPageToken = nextPageToken;
10318
+ const data = await jiraPost(baseUrl, "/rest/api/3/search/jql", auth, request.context.timeoutMs, body);
10285
10319
  const items = data.issues.map((issue) => normalizeIssue(issue, baseUrl, request.context.integrationId));
10286
- const nextStart = data.startAt + data.issues.length;
10287
- const hasMore = nextStart < data.total;
10288
- return { items, hasMore, ...hasMore ? { nextCursor: String(nextStart) } : {} };
10320
+ const hasMore = data.isLast === false;
10321
+ return { items, hasMore, ...hasMore && data.nextPageToken ? { nextCursor: data.nextPageToken } : {} };
10289
10322
  } catch (err) {
10290
10323
  throw normalizeProviderError(err);
10291
10324
  }
package/dist/index.js CHANGED
@@ -18202,7 +18202,7 @@ function buildJql(filters) {
18202
18202
  if (filters?.updatedAfter) clauses.push(`updated >= ${escapeJql(filters.updatedAfter)}`);
18203
18203
  if (filters?.search) clauses.push(`(summary ~ ${escapeJql(filters.search)} OR description ~ ${escapeJql(filters.search)})`);
18204
18204
  if (filters?.providerQuery) clauses.push(`(${filters.providerQuery})`);
18205
- return clauses.join(" AND ") || "ORDER BY updated DESC";
18205
+ return clauses.join(" AND ");
18206
18206
  }
18207
18207
  function normalizeBaseUrl(raw) {
18208
18208
  let url = raw.trim();
@@ -18213,6 +18213,26 @@ function authHeader(email, token) {
18213
18213
  const encoded = typeof Buffer !== "undefined" ? Buffer.from(`${email}:${token}`).toString("base64") : btoa(`${email}:${token}`);
18214
18214
  return `Basic ${encoded}`;
18215
18215
  }
18216
+ async function handleJiraResponse(res) {
18217
+ if (res.status === 401) throw integrationError("INTEGRATION_UNAUTHORIZED");
18218
+ if (res.status === 403) throw integrationError("INTEGRATION_FORBIDDEN");
18219
+ if (res.status === 404) throw integrationError("INTEGRATION_NOT_FOUND");
18220
+ if (res.status === 410) throw integrationError("INTEGRATION_UNAVAILABLE", "Jira API endpoint deprecated (410 Gone).");
18221
+ if (res.status === 429) throw integrationError("INTEGRATION_RATE_LIMITED");
18222
+ if (res.status >= 500) throw integrationError("INTEGRATION_UNAVAILABLE");
18223
+ if (!res.ok) {
18224
+ let detail = "";
18225
+ try {
18226
+ const body = await res.json();
18227
+ const msgs = body.errorMessages?.filter(Boolean) ?? [];
18228
+ const fieldErrs = body.errors ? Object.entries(body.errors).map(([k, v]) => `${k}: ${v}`) : [];
18229
+ detail = [...msgs, ...fieldErrs].join("; ");
18230
+ } catch {
18231
+ }
18232
+ throw integrationError("INTEGRATION_PROVIDER_ERROR", detail || `Jira responded with status ${res.status}.`);
18233
+ }
18234
+ return await res.json();
18235
+ }
18216
18236
  async function jiraFetch(baseUrl, path11, auth, timeoutMs, params) {
18217
18237
  const url = new URL(path11, baseUrl + "/");
18218
18238
  if (params) for (const [k, v] of Object.entries(params)) url.searchParams.set(k, v);
@@ -18224,14 +18244,26 @@ async function jiraFetch(baseUrl, path11, auth, timeoutMs, params) {
18224
18244
  headers: { Authorization: auth, Accept: "application/json" },
18225
18245
  signal: controller.signal
18226
18246
  });
18227
- if (res.status === 401) throw integrationError("INTEGRATION_UNAUTHORIZED");
18228
- if (res.status === 403) throw integrationError("INTEGRATION_FORBIDDEN");
18229
- if (res.status === 404) throw integrationError("INTEGRATION_NOT_FOUND");
18230
- if (res.status === 410) throw integrationError("INTEGRATION_UNAVAILABLE", "Jira API endpoint deprecated (410 Gone).");
18231
- if (res.status === 429) throw integrationError("INTEGRATION_RATE_LIMITED");
18232
- if (res.status >= 500) throw integrationError("INTEGRATION_UNAVAILABLE");
18233
- if (!res.ok) throw integrationError("INTEGRATION_PROVIDER_ERROR", `Jira responded with status ${res.status}.`);
18234
- return await res.json();
18247
+ return await handleJiraResponse(res);
18248
+ } catch (err) {
18249
+ if (err instanceof Error && err.name === "AbortError") throw integrationError("INTEGRATION_TIMEOUT");
18250
+ throw normalizeProviderError(err);
18251
+ } finally {
18252
+ clearTimeout(timer);
18253
+ }
18254
+ }
18255
+ async function jiraPost(baseUrl, path11, auth, timeoutMs, body) {
18256
+ const url = new URL(path11, baseUrl + "/");
18257
+ const controller = new AbortController();
18258
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
18259
+ try {
18260
+ const res = await fetch(url.toString(), {
18261
+ method: "POST",
18262
+ headers: { Authorization: auth, Accept: "application/json", "Content-Type": "application/json" },
18263
+ body: JSON.stringify(body),
18264
+ signal: controller.signal
18265
+ });
18266
+ return await handleJiraResponse(res);
18235
18267
  } catch (err) {
18236
18268
  if (err instanceof Error && err.name === "AbortError") throw integrationError("INTEGRATION_TIMEOUT");
18237
18269
  throw normalizeProviderError(err);
@@ -18350,18 +18382,19 @@ function createJiraAdapter() {
18350
18382
  const auth = authHeader(email, apiToken);
18351
18383
  const jql = buildJql(request.filters);
18352
18384
  const pageSize = Math.min(Math.max(1, request.pageSize ?? DEFAULT_PAGE_SIZE), 100);
18353
- const startAt = request.cursor ? Math.max(0, Number.parseInt(request.cursor, 10) || 0) : 0;
18385
+ const nextPageToken = request.cursor || void 0;
18354
18386
  try {
18355
- const data = await jiraFetch(baseUrl, "/rest/api/3/search/jql", auth, request.context.timeoutMs, {
18356
- jql: jql.startsWith("ORDER BY") ? jql : jql + " ORDER BY updated DESC",
18357
- startAt: String(startAt),
18358
- maxResults: String(pageSize),
18359
- fields: SEARCH_FIELDS
18360
- });
18387
+ const fullJql = jql ? jql + " ORDER BY updated DESC" : "updated >= -30d ORDER BY updated DESC";
18388
+ const body = {
18389
+ jql: fullJql,
18390
+ maxResults: pageSize,
18391
+ fields: SEARCH_FIELDS.split(",")
18392
+ };
18393
+ if (nextPageToken) body.nextPageToken = nextPageToken;
18394
+ const data = await jiraPost(baseUrl, "/rest/api/3/search/jql", auth, request.context.timeoutMs, body);
18361
18395
  const items = data.issues.map((issue) => normalizeIssue(issue, baseUrl, request.context.integrationId));
18362
- const nextStart = data.startAt + data.issues.length;
18363
- const hasMore = nextStart < data.total;
18364
- return { items, hasMore, ...hasMore ? { nextCursor: String(nextStart) } : {} };
18396
+ const hasMore = data.isLast === false;
18397
+ return { items, hasMore, ...hasMore && data.nextPageToken ? { nextCursor: data.nextPageToken } : {} };
18365
18398
  } catch (err) {
18366
18399
  throw normalizeProviderError(err);
18367
18400
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kaddo/cli",
3
- "version": "3.88.2",
3
+ "version": "3.88.4",
4
4
  "description": "Knowledge Driven Development toolkit",
5
5
  "license": "MIT",
6
6
  "repository": {