@kaddo/cli 3.86.0 → 3.88.0
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/index.js
CHANGED
|
@@ -12730,6 +12730,7 @@ function parseWorkItemSource(frontmatter) {
|
|
|
12730
12730
|
integration: optStr(obj.integration) ?? optStr(frontmatter.source_integration),
|
|
12731
12731
|
url: optStr(obj.url) ?? optStr(frontmatter.source_url),
|
|
12732
12732
|
imported_at: optStr(obj.imported_at) ?? optStr(frontmatter.source_imported_at),
|
|
12733
|
+
external_updated_at: optStr(obj.external_updated_at) ?? optStr(frontmatter.source_external_updated_at),
|
|
12733
12734
|
synced_at: optStr(obj.synced_at) ?? optStr(frontmatter.source_synced_at),
|
|
12734
12735
|
inferred: obj.inferred === true || obj.inferred === "true",
|
|
12735
12736
|
reason: t && !isValidSource(t) ? `Invalid source type in object: "${t}".` : void 0
|
|
@@ -12745,6 +12746,7 @@ function parseWorkItemSource(frontmatter) {
|
|
|
12745
12746
|
provider: optStr(frontmatter.source_provider),
|
|
12746
12747
|
url: optStr(frontmatter.source_url),
|
|
12747
12748
|
imported_at: optStr(frontmatter.source_imported_at),
|
|
12749
|
+
external_updated_at: optStr(frontmatter.source_external_updated_at),
|
|
12748
12750
|
synced_at: optStr(frontmatter.source_synced_at),
|
|
12749
12751
|
inferred: false
|
|
12750
12752
|
};
|
|
@@ -12758,6 +12760,7 @@ function parseWorkItemSource(frontmatter) {
|
|
|
12758
12760
|
provider: optStr(frontmatter.source_provider),
|
|
12759
12761
|
url: optStr(frontmatter.source_url),
|
|
12760
12762
|
imported_at: optStr(frontmatter.source_imported_at),
|
|
12763
|
+
external_updated_at: optStr(frontmatter.source_external_updated_at),
|
|
12761
12764
|
synced_at: optStr(frontmatter.source_synced_at),
|
|
12762
12765
|
inferred: true,
|
|
12763
12766
|
reason: `Invalid source value: "${raw}".`
|
|
@@ -17530,6 +17533,7 @@ function createWorkItem(dir, opts) {
|
|
|
17530
17533
|
affected_modules: [],
|
|
17531
17534
|
summary: intent
|
|
17532
17535
|
};
|
|
17536
|
+
if (opts.originalSnapshot) data.original_snapshot = opts.originalSnapshot;
|
|
17533
17537
|
const answers = opts.answers ?? {};
|
|
17534
17538
|
const hasAnswers = Object.values(answers).some((v) => v?.trim());
|
|
17535
17539
|
const body = hasAnswers ? captureBody(title, type, answers) : freshBody({
|
|
@@ -17598,6 +17602,10 @@ function defaultMessageFor(code) {
|
|
|
17598
17602
|
function integrationError(code, message) {
|
|
17599
17603
|
return new IntegrationError(code, message ?? defaultMessageFor(code));
|
|
17600
17604
|
}
|
|
17605
|
+
function normalizeProviderError(err, fallback = "INTEGRATION_PROVIDER_ERROR") {
|
|
17606
|
+
if (err instanceof IntegrationError) return err;
|
|
17607
|
+
return new IntegrationError(fallback, defaultMessageFor(fallback));
|
|
17608
|
+
}
|
|
17601
17609
|
|
|
17602
17610
|
// ../integrations/src/identity.ts
|
|
17603
17611
|
function externalIdentityKey(integrationId, externalId) {
|
|
@@ -17667,6 +17675,11 @@ function parseFilters(raw) {
|
|
|
17667
17675
|
const o = raw;
|
|
17668
17676
|
const filters = {};
|
|
17669
17677
|
let hasAny = false;
|
|
17678
|
+
const projects = toStringArray4(o.projects);
|
|
17679
|
+
if (projects?.length) {
|
|
17680
|
+
filters.projects = projects;
|
|
17681
|
+
hasAny = true;
|
|
17682
|
+
}
|
|
17670
17683
|
const types = toStringArray4(o.types);
|
|
17671
17684
|
if (types?.length) {
|
|
17672
17685
|
filters.types = types;
|
|
@@ -17761,6 +17774,7 @@ function mergeFilters(base, overlay) {
|
|
|
17761
17774
|
if (!base) return { ...overlay };
|
|
17762
17775
|
if (!overlay) return { ...base };
|
|
17763
17776
|
return {
|
|
17777
|
+
projects: overlay.projects?.length ? overlay.projects : base.projects,
|
|
17764
17778
|
types: overlay.types?.length ? overlay.types : base.types,
|
|
17765
17779
|
statuses: overlay.statuses?.length ? overlay.statuses : base.statuses,
|
|
17766
17780
|
labels: overlay.labels?.length ? overlay.labels : base.labels,
|
|
@@ -18120,10 +18134,259 @@ function createMockAdapter(opts = {}) {
|
|
|
18120
18134
|
};
|
|
18121
18135
|
}
|
|
18122
18136
|
|
|
18137
|
+
// ../integrations/src/jira-adapter.ts
|
|
18138
|
+
var JIRA_ADAPTER_ID = "jira";
|
|
18139
|
+
function adfToMarkdown(node) {
|
|
18140
|
+
if (!node) return "";
|
|
18141
|
+
if (node.type === "text") {
|
|
18142
|
+
let t = node.text ?? "";
|
|
18143
|
+
for (const m of node.marks ?? []) {
|
|
18144
|
+
if (m.type === "strong") t = `**${t}**`;
|
|
18145
|
+
else if (m.type === "em") t = `*${t}*`;
|
|
18146
|
+
else if (m.type === "code") t = `\`${t}\``;
|
|
18147
|
+
else if (m.type === "strike") t = `~~${t}~~`;
|
|
18148
|
+
}
|
|
18149
|
+
return t;
|
|
18150
|
+
}
|
|
18151
|
+
const children = (node.content ?? []).map(adfToMarkdown).join("");
|
|
18152
|
+
switch (node.type) {
|
|
18153
|
+
case "doc":
|
|
18154
|
+
return children.trim();
|
|
18155
|
+
case "paragraph":
|
|
18156
|
+
return children + "\n\n";
|
|
18157
|
+
case "heading": {
|
|
18158
|
+
const level = Math.min(Number(node.attrs?.level) || 1, 6);
|
|
18159
|
+
return "#".repeat(level) + " " + children.trim() + "\n\n";
|
|
18160
|
+
}
|
|
18161
|
+
case "bulletList":
|
|
18162
|
+
return children;
|
|
18163
|
+
case "orderedList":
|
|
18164
|
+
return children;
|
|
18165
|
+
case "listItem":
|
|
18166
|
+
return "- " + children.trim() + "\n";
|
|
18167
|
+
case "blockquote":
|
|
18168
|
+
return children.split("\n").filter(Boolean).map((l) => "> " + l).join("\n") + "\n\n";
|
|
18169
|
+
case "codeBlock":
|
|
18170
|
+
return "```\n" + children + "```\n\n";
|
|
18171
|
+
case "rule":
|
|
18172
|
+
return "---\n\n";
|
|
18173
|
+
case "hardBreak":
|
|
18174
|
+
return "\n";
|
|
18175
|
+
case "mediaGroup":
|
|
18176
|
+
case "mediaSingle":
|
|
18177
|
+
case "media":
|
|
18178
|
+
return "";
|
|
18179
|
+
default:
|
|
18180
|
+
return children;
|
|
18181
|
+
}
|
|
18182
|
+
}
|
|
18183
|
+
function normalizeDescription(field) {
|
|
18184
|
+
if (!field) return void 0;
|
|
18185
|
+
if (typeof field === "string") return field || void 0;
|
|
18186
|
+
if (typeof field === "object" && field.type === "doc") {
|
|
18187
|
+
const md = adfToMarkdown(field);
|
|
18188
|
+
return md || void 0;
|
|
18189
|
+
}
|
|
18190
|
+
return void 0;
|
|
18191
|
+
}
|
|
18192
|
+
function escapeJql(value) {
|
|
18193
|
+
return '"' + value.replace(/\\/g, "\\\\").replace(/"/g, '\\"') + '"';
|
|
18194
|
+
}
|
|
18195
|
+
function buildJql(filters) {
|
|
18196
|
+
const clauses = [];
|
|
18197
|
+
if (filters?.projects?.length) clauses.push(`project IN (${filters.projects.map(escapeJql).join(", ")})`);
|
|
18198
|
+
if (filters?.types?.length) clauses.push(`issuetype IN (${filters.types.map(escapeJql).join(", ")})`);
|
|
18199
|
+
if (filters?.statuses?.length) clauses.push(`status IN (${filters.statuses.map(escapeJql).join(", ")})`);
|
|
18200
|
+
if (filters?.labels?.length) clauses.push(`labels IN (${filters.labels.map(escapeJql).join(", ")})`);
|
|
18201
|
+
if (filters?.assignees?.length) clauses.push(`assignee IN (${filters.assignees.map(escapeJql).join(", ")})`);
|
|
18202
|
+
if (filters?.updatedAfter) clauses.push(`updated >= ${escapeJql(filters.updatedAfter)}`);
|
|
18203
|
+
if (filters?.search) clauses.push(`(summary ~ ${escapeJql(filters.search)} OR description ~ ${escapeJql(filters.search)})`);
|
|
18204
|
+
if (filters?.providerQuery) clauses.push(`(${filters.providerQuery})`);
|
|
18205
|
+
return clauses.join(" AND ") || "ORDER BY updated DESC";
|
|
18206
|
+
}
|
|
18207
|
+
function normalizeBaseUrl(raw) {
|
|
18208
|
+
let url = raw.trim();
|
|
18209
|
+
if (url.endsWith("/")) url = url.slice(0, -1);
|
|
18210
|
+
return url;
|
|
18211
|
+
}
|
|
18212
|
+
function authHeader(email, token) {
|
|
18213
|
+
const encoded = typeof Buffer !== "undefined" ? Buffer.from(`${email}:${token}`).toString("base64") : btoa(`${email}:${token}`);
|
|
18214
|
+
return `Basic ${encoded}`;
|
|
18215
|
+
}
|
|
18216
|
+
async function jiraFetch(baseUrl, path11, auth, timeoutMs, params) {
|
|
18217
|
+
const url = new URL(path11, baseUrl + "/");
|
|
18218
|
+
if (params) for (const [k, v] of Object.entries(params)) url.searchParams.set(k, v);
|
|
18219
|
+
const controller = new AbortController();
|
|
18220
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
18221
|
+
try {
|
|
18222
|
+
const res = await fetch(url.toString(), {
|
|
18223
|
+
method: "GET",
|
|
18224
|
+
headers: { Authorization: auth, Accept: "application/json" },
|
|
18225
|
+
signal: controller.signal
|
|
18226
|
+
});
|
|
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 === 429) throw integrationError("INTEGRATION_RATE_LIMITED");
|
|
18231
|
+
if (res.status >= 500) throw integrationError("INTEGRATION_UNAVAILABLE");
|
|
18232
|
+
if (!res.ok) throw integrationError("INTEGRATION_PROVIDER_ERROR", `Jira responded with status ${res.status}.`);
|
|
18233
|
+
return await res.json();
|
|
18234
|
+
} catch (err) {
|
|
18235
|
+
if (err instanceof Error && err.name === "AbortError") throw integrationError("INTEGRATION_TIMEOUT");
|
|
18236
|
+
throw normalizeProviderError(err);
|
|
18237
|
+
} finally {
|
|
18238
|
+
clearTimeout(timer);
|
|
18239
|
+
}
|
|
18240
|
+
}
|
|
18241
|
+
function normalizeIssue(issue, baseUrl, integrationId) {
|
|
18242
|
+
const f = issue.fields;
|
|
18243
|
+
const issueType = f.issuetype;
|
|
18244
|
+
const status = f.status;
|
|
18245
|
+
const assignee = f.assignee;
|
|
18246
|
+
const reporter = f.reporter;
|
|
18247
|
+
const priority = f.priority;
|
|
18248
|
+
const project = f.project;
|
|
18249
|
+
const parent = f.parent;
|
|
18250
|
+
const components = f.components;
|
|
18251
|
+
const labels = f.labels;
|
|
18252
|
+
return {
|
|
18253
|
+
externalId: issue.key,
|
|
18254
|
+
provider: JIRA_ADAPTER_ID,
|
|
18255
|
+
title: f.summary ?? issue.key,
|
|
18256
|
+
description: normalizeDescription(f.description),
|
|
18257
|
+
type: issueType?.name,
|
|
18258
|
+
status: status?.name,
|
|
18259
|
+
url: `${baseUrl}/browse/${issue.key}`,
|
|
18260
|
+
author: reporter ? { name: reporter.displayName, email: reporter.emailAddress, id: reporter.accountId } : void 0,
|
|
18261
|
+
assignees: assignee ? [{ name: assignee.displayName, email: assignee.emailAddress, id: assignee.accountId }] : void 0,
|
|
18262
|
+
labels,
|
|
18263
|
+
createdAt: f.created,
|
|
18264
|
+
updatedAt: f.updated,
|
|
18265
|
+
project: project ? { key: project.key, name: project.name, id: project.id } : void 0,
|
|
18266
|
+
rawMetadata: {
|
|
18267
|
+
...priority?.name ? { priority: priority.name } : {},
|
|
18268
|
+
...parent?.key ? { parent: parent.key } : {},
|
|
18269
|
+
...components?.length ? { components: components.map((c) => c.name).filter(Boolean) } : {}
|
|
18270
|
+
}
|
|
18271
|
+
};
|
|
18272
|
+
}
|
|
18273
|
+
var SEARCH_FIELDS = "summary,description,issuetype,status,assignee,reporter,priority,labels,project,parent,components,created,updated";
|
|
18274
|
+
var DEFAULT_PAGE_SIZE = 50;
|
|
18275
|
+
var metadata = {
|
|
18276
|
+
id: JIRA_ADAPTER_ID,
|
|
18277
|
+
displayName: "Jira",
|
|
18278
|
+
version: "1.0.0",
|
|
18279
|
+
description: "Connect Jira Cloud work items to Kaddo for discovery, import and refinement.",
|
|
18280
|
+
icon: "jira",
|
|
18281
|
+
configSchema: {
|
|
18282
|
+
baseUrl: {
|
|
18283
|
+
type: "url",
|
|
18284
|
+
required: true,
|
|
18285
|
+
label: "Jira Site URL",
|
|
18286
|
+
description: "The URL of the Jira Cloud site.",
|
|
18287
|
+
placeholder: "https://company.atlassian.net"
|
|
18288
|
+
},
|
|
18289
|
+
email: {
|
|
18290
|
+
type: "string",
|
|
18291
|
+
required: true,
|
|
18292
|
+
label: "Email",
|
|
18293
|
+
description: "Email associated with the Jira API token.",
|
|
18294
|
+
placeholder: "user@company.com"
|
|
18295
|
+
}
|
|
18296
|
+
},
|
|
18297
|
+
secretSchema: {
|
|
18298
|
+
apiToken: {
|
|
18299
|
+
type: "password",
|
|
18300
|
+
required: true,
|
|
18301
|
+
label: "API Token",
|
|
18302
|
+
description: "Jira API token for authentication. Generate one at id.atlassian.com."
|
|
18303
|
+
}
|
|
18304
|
+
},
|
|
18305
|
+
filterCapabilities: {
|
|
18306
|
+
projects: { supported: true, multiple: true },
|
|
18307
|
+
types: { supported: true, multiple: true },
|
|
18308
|
+
statuses: { supported: true, multiple: true },
|
|
18309
|
+
labels: { supported: true, multiple: true },
|
|
18310
|
+
assignees: { supported: true, multiple: true },
|
|
18311
|
+
updatedAfter: { supported: true },
|
|
18312
|
+
search: { supported: true },
|
|
18313
|
+
providerQuery: { supported: true, label: "JQL" }
|
|
18314
|
+
}
|
|
18315
|
+
};
|
|
18316
|
+
var capabilities = {
|
|
18317
|
+
workItems: { list: true, read: true, import: true, write: false, statusSync: false, comments: false, webhooks: false }
|
|
18318
|
+
};
|
|
18319
|
+
function resolveConfig(context) {
|
|
18320
|
+
const baseUrl = context.config.baseUrl;
|
|
18321
|
+
const email = context.config.email;
|
|
18322
|
+
const apiToken = context.credentials.apiToken;
|
|
18323
|
+
if (typeof baseUrl !== "string" || !baseUrl) throw integrationError("INTEGRATION_CONFIG_INVALID", "Jira Site URL is required.");
|
|
18324
|
+
if (typeof email !== "string" || !email) throw integrationError("INTEGRATION_CONFIG_INVALID", "Email is required.");
|
|
18325
|
+
if (!apiToken) throw integrationError("INTEGRATION_CONFIG_INVALID", "API Token is required.");
|
|
18326
|
+
return { baseUrl: normalizeBaseUrl(baseUrl), email, apiToken };
|
|
18327
|
+
}
|
|
18328
|
+
function createJiraAdapter() {
|
|
18329
|
+
return {
|
|
18330
|
+
id: JIRA_ADAPTER_ID,
|
|
18331
|
+
metadata,
|
|
18332
|
+
capabilities,
|
|
18333
|
+
async verifyConnection(context) {
|
|
18334
|
+
const checkedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
18335
|
+
try {
|
|
18336
|
+
const { baseUrl, email, apiToken } = resolveConfig(context);
|
|
18337
|
+
const auth = authHeader(email, apiToken);
|
|
18338
|
+
await jiraFetch(baseUrl, "/rest/api/3/myself", auth, context.timeoutMs);
|
|
18339
|
+
return { status: "available", checkedAt };
|
|
18340
|
+
} catch (err) {
|
|
18341
|
+
const ie = normalizeProviderError(err);
|
|
18342
|
+
if (ie.code === "INTEGRATION_UNAUTHORIZED") return { status: "unauthorized", message: "Check the configured email and API token.", checkedAt };
|
|
18343
|
+
if (ie.code === "INTEGRATION_CONFIG_INVALID") return { status: "invalid-config", message: ie.safeMessage, checkedAt };
|
|
18344
|
+
return { status: "unavailable", message: ie.safeMessage, checkedAt };
|
|
18345
|
+
}
|
|
18346
|
+
},
|
|
18347
|
+
async listWorkItems(request) {
|
|
18348
|
+
const { baseUrl, email, apiToken } = resolveConfig(request.context);
|
|
18349
|
+
const auth = authHeader(email, apiToken);
|
|
18350
|
+
const jql = buildJql(request.filters);
|
|
18351
|
+
const pageSize = Math.min(Math.max(1, request.pageSize ?? DEFAULT_PAGE_SIZE), 100);
|
|
18352
|
+
const startAt = request.cursor ? Math.max(0, Number.parseInt(request.cursor, 10) || 0) : 0;
|
|
18353
|
+
try {
|
|
18354
|
+
const data = await jiraFetch(baseUrl, "/rest/api/3/search", auth, request.context.timeoutMs, {
|
|
18355
|
+
jql: jql.startsWith("ORDER BY") ? jql : jql + " ORDER BY updated DESC",
|
|
18356
|
+
startAt: String(startAt),
|
|
18357
|
+
maxResults: String(pageSize),
|
|
18358
|
+
fields: SEARCH_FIELDS
|
|
18359
|
+
});
|
|
18360
|
+
const items = data.issues.map((issue) => normalizeIssue(issue, baseUrl, request.context.integrationId));
|
|
18361
|
+
const nextStart = data.startAt + data.issues.length;
|
|
18362
|
+
const hasMore = nextStart < data.total;
|
|
18363
|
+
return { items, hasMore, ...hasMore ? { nextCursor: String(nextStart) } : {} };
|
|
18364
|
+
} catch (err) {
|
|
18365
|
+
throw normalizeProviderError(err);
|
|
18366
|
+
}
|
|
18367
|
+
},
|
|
18368
|
+
async getWorkItem(request) {
|
|
18369
|
+
const { baseUrl, email, apiToken } = resolveConfig(request.context);
|
|
18370
|
+
const auth = authHeader(email, apiToken);
|
|
18371
|
+
try {
|
|
18372
|
+
const issue = await jiraFetch(baseUrl, `/rest/api/3/issue/${encodeURIComponent(request.externalId)}`, auth, request.context.timeoutMs, {
|
|
18373
|
+
fields: SEARCH_FIELDS
|
|
18374
|
+
});
|
|
18375
|
+
return normalizeIssue(issue, baseUrl, request.context.integrationId);
|
|
18376
|
+
} catch (err) {
|
|
18377
|
+
const ie = normalizeProviderError(err);
|
|
18378
|
+
if (ie.code === "INTEGRATION_NOT_FOUND") return null;
|
|
18379
|
+
throw ie;
|
|
18380
|
+
}
|
|
18381
|
+
}
|
|
18382
|
+
};
|
|
18383
|
+
}
|
|
18384
|
+
|
|
18123
18385
|
// ../integrations/src/index.ts
|
|
18124
18386
|
function createDefaultRegistry() {
|
|
18125
18387
|
const registry2 = new IntegrationRegistry();
|
|
18126
18388
|
registry2.register(createMockAdapter());
|
|
18389
|
+
registry2.register(createJiraAdapter());
|
|
18127
18390
|
return registry2;
|
|
18128
18391
|
}
|
|
18129
18392
|
|
|
@@ -18291,7 +18554,18 @@ ${item.description}` : item.title;
|
|
|
18291
18554
|
integration: id,
|
|
18292
18555
|
id: externalId,
|
|
18293
18556
|
url: item.url,
|
|
18294
|
-
imported_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
18557
|
+
imported_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
18558
|
+
external_updated_at: item.updatedAt
|
|
18559
|
+
},
|
|
18560
|
+
originalSnapshot: {
|
|
18561
|
+
title: item.title,
|
|
18562
|
+
description: item.description,
|
|
18563
|
+
type: item.type,
|
|
18564
|
+
status: item.status,
|
|
18565
|
+
labels: item.labels,
|
|
18566
|
+
assignee: item.assignees?.[0]?.name,
|
|
18567
|
+
created_at: item.createdAt,
|
|
18568
|
+
updated_at: item.updatedAt
|
|
18295
18569
|
}
|
|
18296
18570
|
});
|
|
18297
18571
|
return { workItemId: created.id, created: true, preview, path: created.path };
|