@mgsoftwarebv/mcp-server-bridge 3.3.7 → 3.3.8
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 +135 -44
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -92216,13 +92216,13 @@ function construct(client, config3 = {}) {
|
|
|
92216
92216
|
};
|
|
92217
92217
|
}
|
|
92218
92218
|
const session = new PostgresJsSession(client, dialect, schema, { logger: logger2, cache: config3.cache });
|
|
92219
|
-
const
|
|
92220
|
-
|
|
92221
|
-
|
|
92222
|
-
if (
|
|
92223
|
-
|
|
92219
|
+
const db3 = new PostgresJsDatabase(dialect, session, schema);
|
|
92220
|
+
db3.$client = client;
|
|
92221
|
+
db3.$cache = config3.cache;
|
|
92222
|
+
if (db3.$cache) {
|
|
92223
|
+
db3.$cache["invalidate"] = config3.cache?.onMutate;
|
|
92224
92224
|
}
|
|
92225
|
-
return
|
|
92225
|
+
return db3;
|
|
92226
92226
|
}
|
|
92227
92227
|
function drizzle(...params) {
|
|
92228
92228
|
if (typeof params[0] === "string") {
|
|
@@ -103378,12 +103378,12 @@ var createJobDb = () => {
|
|
|
103378
103378
|
connect_timeout: 10
|
|
103379
103379
|
// 10 second connection timeout
|
|
103380
103380
|
});
|
|
103381
|
-
const
|
|
103381
|
+
const db3 = drizzle(jobPool, {
|
|
103382
103382
|
schema: schema_exports,
|
|
103383
103383
|
casing: "snake_case"
|
|
103384
103384
|
});
|
|
103385
103385
|
return {
|
|
103386
|
-
db:
|
|
103386
|
+
db: db3,
|
|
103387
103387
|
disconnect: () => jobPool.end()
|
|
103388
103388
|
};
|
|
103389
103389
|
};
|
|
@@ -120218,6 +120218,118 @@ ${created.projectId ? `Project ID: ${created.projectId}
|
|
|
120218
120218
|
};
|
|
120219
120219
|
}
|
|
120220
120220
|
|
|
120221
|
+
// src/utils/ticket-number.ts
|
|
120222
|
+
async function isTicketNumberTaken(ticketDb, teamId, ticketNumber, excludeTicketId) {
|
|
120223
|
+
const conditions = [
|
|
120224
|
+
eq(schema_exports.tickets.teamId, teamId),
|
|
120225
|
+
eq(schema_exports.tickets.ticketNumber, ticketNumber),
|
|
120226
|
+
eq(schema_exports.tickets.isDeleted, false)
|
|
120227
|
+
];
|
|
120228
|
+
if (excludeTicketId) {
|
|
120229
|
+
conditions.push(ne(schema_exports.tickets.id, excludeTicketId));
|
|
120230
|
+
}
|
|
120231
|
+
const [existing] = await ticketDb.select({ id: schema_exports.tickets.id }).from(schema_exports.tickets).where(and(...conditions)).limit(1);
|
|
120232
|
+
return Boolean(existing);
|
|
120233
|
+
}
|
|
120234
|
+
async function getMaxProjectSequence(ticketDb, teamId, pattern, excludeTicketId) {
|
|
120235
|
+
const conditions = [
|
|
120236
|
+
eq(schema_exports.tickets.teamId, teamId),
|
|
120237
|
+
like(schema_exports.tickets.ticketNumber, pattern),
|
|
120238
|
+
eq(schema_exports.tickets.isDeleted, false)
|
|
120239
|
+
];
|
|
120240
|
+
if (excludeTicketId) {
|
|
120241
|
+
conditions.push(ne(schema_exports.tickets.id, excludeTicketId));
|
|
120242
|
+
}
|
|
120243
|
+
const [row] = await ticketDb.select({
|
|
120244
|
+
maxSeq: sql`coalesce(max(
|
|
120245
|
+
case
|
|
120246
|
+
when split_part(${schema_exports.tickets.ticketNumber}, '-', 3) ~ '^[0-9]+$'
|
|
120247
|
+
then split_part(${schema_exports.tickets.ticketNumber}, '-', 3)::integer
|
|
120248
|
+
else null
|
|
120249
|
+
end
|
|
120250
|
+
), 0)`
|
|
120251
|
+
}).from(schema_exports.tickets).where(and(...conditions));
|
|
120252
|
+
return Number(row?.maxSeq ?? 0);
|
|
120253
|
+
}
|
|
120254
|
+
async function getMaxSimpleSequence(ticketDb, teamId, currentYear, excludeTicketId) {
|
|
120255
|
+
const conditions = [
|
|
120256
|
+
eq(schema_exports.tickets.teamId, teamId),
|
|
120257
|
+
like(schema_exports.tickets.ticketNumber, `${currentYear}-%`),
|
|
120258
|
+
eq(schema_exports.tickets.isDeleted, false)
|
|
120259
|
+
];
|
|
120260
|
+
if (excludeTicketId) {
|
|
120261
|
+
conditions.push(ne(schema_exports.tickets.id, excludeTicketId));
|
|
120262
|
+
}
|
|
120263
|
+
const [row] = await ticketDb.select({
|
|
120264
|
+
maxSeq: sql`coalesce(max(
|
|
120265
|
+
case
|
|
120266
|
+
when ${schema_exports.tickets.ticketNumber} ~ ${`^${currentYear}-[0-9]+$`}
|
|
120267
|
+
then split_part(${schema_exports.tickets.ticketNumber}, '-', 2)::integer
|
|
120268
|
+
else null
|
|
120269
|
+
end
|
|
120270
|
+
), 0)`
|
|
120271
|
+
}).from(schema_exports.tickets).where(and(...conditions));
|
|
120272
|
+
return Number(row?.maxSeq ?? 0);
|
|
120273
|
+
}
|
|
120274
|
+
async function resolveUniqueTicketNumber(ticketDb, teamId, buildNumber, startSequence, excludeTicketId) {
|
|
120275
|
+
let sequence = startSequence;
|
|
120276
|
+
for (let attempt = 0; attempt < 100; attempt += 1) {
|
|
120277
|
+
const ticketNumber = buildNumber(sequence);
|
|
120278
|
+
const taken = await isTicketNumberTaken(
|
|
120279
|
+
ticketDb,
|
|
120280
|
+
teamId,
|
|
120281
|
+
ticketNumber,
|
|
120282
|
+
excludeTicketId
|
|
120283
|
+
);
|
|
120284
|
+
if (!taken) {
|
|
120285
|
+
return ticketNumber;
|
|
120286
|
+
}
|
|
120287
|
+
sequence += 1;
|
|
120288
|
+
}
|
|
120289
|
+
throw new Error("Failed to generate a unique ticket number");
|
|
120290
|
+
}
|
|
120291
|
+
async function generateTicketNumber(ticketDb, teamId, projectId, options) {
|
|
120292
|
+
const currentYear = (/* @__PURE__ */ new Date()).getFullYear();
|
|
120293
|
+
const excludeTicketId = options?.excludeTicketId ?? null;
|
|
120294
|
+
if (projectId) {
|
|
120295
|
+
const [project] = await ticketDb.select({ name: schema_exports.projects.name }).from(schema_exports.projects).where(eq(schema_exports.projects.id, projectId)).limit(1);
|
|
120296
|
+
if (project?.name) {
|
|
120297
|
+
const projectAbbreviation = generateProjectAbbreviation(project.name);
|
|
120298
|
+
const pattern = `${currentYear}-${projectAbbreviation}-%`;
|
|
120299
|
+
const maxSequence2 = await getMaxProjectSequence(
|
|
120300
|
+
ticketDb,
|
|
120301
|
+
teamId,
|
|
120302
|
+
pattern,
|
|
120303
|
+
excludeTicketId
|
|
120304
|
+
);
|
|
120305
|
+
let nextSequence = maxSequence2 + 1;
|
|
120306
|
+
if (projectAbbreviation === "MBC" && nextSequence < 100001) {
|
|
120307
|
+
nextSequence = 100001;
|
|
120308
|
+
}
|
|
120309
|
+
return resolveUniqueTicketNumber(
|
|
120310
|
+
ticketDb,
|
|
120311
|
+
teamId,
|
|
120312
|
+
(sequence) => `${currentYear}-${projectAbbreviation}-${String(sequence).padStart(3, "0")}`,
|
|
120313
|
+
nextSequence,
|
|
120314
|
+
excludeTicketId
|
|
120315
|
+
);
|
|
120316
|
+
}
|
|
120317
|
+
}
|
|
120318
|
+
const maxSequence = await getMaxSimpleSequence(
|
|
120319
|
+
ticketDb,
|
|
120320
|
+
teamId,
|
|
120321
|
+
currentYear,
|
|
120322
|
+
excludeTicketId
|
|
120323
|
+
);
|
|
120324
|
+
return resolveUniqueTicketNumber(
|
|
120325
|
+
ticketDb,
|
|
120326
|
+
teamId,
|
|
120327
|
+
(sequence) => `${currentYear}-${String(sequence).padStart(3, "0")}`,
|
|
120328
|
+
maxSequence + 1,
|
|
120329
|
+
excludeTicketId
|
|
120330
|
+
);
|
|
120331
|
+
}
|
|
120332
|
+
|
|
120221
120333
|
// src/tools/ticket-update.ts
|
|
120222
120334
|
async function handleUpdateTicket(input) {
|
|
120223
120335
|
const ctx = getAuthContext();
|
|
@@ -120253,6 +120365,7 @@ async function handleUpdateTicket(input) {
|
|
|
120253
120365
|
updateValues.priority = input.priority;
|
|
120254
120366
|
}
|
|
120255
120367
|
if (input.type !== void 0) updateValues.type = input.type;
|
|
120368
|
+
const projectExplicitlyChanged = input.projectId !== void 0 && input.projectId !== ticket.projectId;
|
|
120256
120369
|
if (input.projectId !== void 0) updateValues.projectId = input.projectId;
|
|
120257
120370
|
if (input.customerId !== void 0) {
|
|
120258
120371
|
updateValues.customerId = input.customerId;
|
|
@@ -120267,6 +120380,14 @@ async function handleUpdateTicket(input) {
|
|
|
120267
120380
|
updateValues.dueDate = input.dueDate;
|
|
120268
120381
|
updateValues.dueDateAllDay = input.dueDate ? true : false;
|
|
120269
120382
|
}
|
|
120383
|
+
if (projectExplicitlyChanged) {
|
|
120384
|
+
updateValues.ticketNumber = await generateTicketNumber(
|
|
120385
|
+
db,
|
|
120386
|
+
ticket.teamId,
|
|
120387
|
+
input.projectId,
|
|
120388
|
+
{ excludeTicketId: ticket.id }
|
|
120389
|
+
);
|
|
120390
|
+
}
|
|
120270
120391
|
let deadlineChange = null;
|
|
120271
120392
|
if (input.dueDate !== void 0) {
|
|
120272
120393
|
deadlineChange = await syncTicketDeadline(
|
|
@@ -120336,7 +120457,11 @@ async function handleUpdateTicket(input) {
|
|
|
120336
120457
|
changes.push("title updated");
|
|
120337
120458
|
}
|
|
120338
120459
|
if (input.description !== void 0) changes.push("description updated");
|
|
120339
|
-
if (input.projectId !== void 0)
|
|
120460
|
+
if (input.projectId !== void 0) {
|
|
120461
|
+
changes.push(
|
|
120462
|
+
projectExplicitlyChanged ? `project updated (renumbered to ${String(updateValues.ticketNumber ?? ticket.ticketNumber)})` : "project updated"
|
|
120463
|
+
);
|
|
120464
|
+
}
|
|
120340
120465
|
if (input.customerId !== void 0) changes.push("customer updated");
|
|
120341
120466
|
if (input.estimatedHours !== void 0) changes.push("estimated hours updated");
|
|
120342
120467
|
if (deadlineChange) changes.push(deadlineChange);
|
|
@@ -120768,13 +120893,10 @@ async function handleCreateTicket(input) {
|
|
|
120768
120893
|
} = input;
|
|
120769
120894
|
const resolved = await resolveTeamId(input.teamId);
|
|
120770
120895
|
if (!resolved.ok) return resolved.response;
|
|
120771
|
-
const year2 = (/* @__PURE__ */ new Date()).getFullYear();
|
|
120772
120896
|
let resolvedTeamId = resolved.teamId;
|
|
120773
120897
|
let resolvedCustomerId = customerId;
|
|
120774
|
-
let projectAbbreviation = "";
|
|
120775
120898
|
if (projectId) {
|
|
120776
120899
|
const [project] = await db.select({
|
|
120777
|
-
name: schema_exports.projects.name,
|
|
120778
120900
|
teamId: schema_exports.projects.teamId,
|
|
120779
120901
|
customerId: schema_exports.projects.customerId
|
|
120780
120902
|
}).from(schema_exports.projects).where(eq(schema_exports.projects.id, projectId)).limit(1);
|
|
@@ -120787,40 +120909,9 @@ async function handleCreateTicket(input) {
|
|
|
120787
120909
|
if (!resolvedCustomerId && project.customerId) {
|
|
120788
120910
|
resolvedCustomerId = project.customerId;
|
|
120789
120911
|
}
|
|
120790
|
-
if (project.name) {
|
|
120791
|
-
const upper = project.name.toUpperCase().replace(/[^A-Z0-9\s]/g, "");
|
|
120792
|
-
const words = upper.split(/\s+/).filter(Boolean);
|
|
120793
|
-
if (words.length >= 2) {
|
|
120794
|
-
projectAbbreviation = words.slice(0, 2).map((w2) => w2.substring(0, 3)).join("").substring(0, 5);
|
|
120795
|
-
} else if (words.length === 1 && words[0]) {
|
|
120796
|
-
projectAbbreviation = words[0].substring(0, 5);
|
|
120797
|
-
}
|
|
120798
|
-
}
|
|
120799
|
-
}
|
|
120800
|
-
}
|
|
120801
|
-
let ticketNumber;
|
|
120802
|
-
if (projectId && projectAbbreviation) {
|
|
120803
|
-
const pattern = `${year2}-${projectAbbreviation}-%`;
|
|
120804
|
-
const [highest] = await db.select({ ticketNumber: schema_exports.tickets.ticketNumber }).from(schema_exports.tickets).where(
|
|
120805
|
-
and(
|
|
120806
|
-
eq(schema_exports.tickets.projectId, projectId),
|
|
120807
|
-
ilike(schema_exports.tickets.ticketNumber, pattern)
|
|
120808
|
-
)
|
|
120809
|
-
).orderBy(desc(schema_exports.tickets.ticketNumber)).limit(1);
|
|
120810
|
-
let nextSequence = 1;
|
|
120811
|
-
if (highest?.ticketNumber) {
|
|
120812
|
-
const parts = highest.ticketNumber.split("-");
|
|
120813
|
-
if (parts.length === 3 && parts[2]) {
|
|
120814
|
-
const lastSeq = Number.parseInt(parts[2], 10);
|
|
120815
|
-
if (!Number.isNaN(lastSeq)) nextSequence = lastSeq + 1;
|
|
120816
|
-
}
|
|
120817
120912
|
}
|
|
120818
|
-
ticketNumber = `${year2}-${projectAbbreviation}-${String(nextSequence).padStart(3, "0")}`;
|
|
120819
|
-
} else {
|
|
120820
|
-
const [countRow] = await db.select({ n: sql`count(*)::int` }).from(schema_exports.tickets).where(eq(schema_exports.tickets.teamId, resolvedTeamId));
|
|
120821
|
-
const count = Number(countRow?.n ?? 0);
|
|
120822
|
-
ticketNumber = `${year2}-${String(count + 1).padStart(3, "0")}`;
|
|
120823
120913
|
}
|
|
120914
|
+
const ticketNumber = await generateTicketNumber(db, resolvedTeamId, projectId);
|
|
120824
120915
|
const [created] = await db.insert(schema_exports.tickets).values({
|
|
120825
120916
|
teamId: resolvedTeamId,
|
|
120826
120917
|
ticketNumber,
|