@rubytech/create-maxy-code 0.1.331 → 0.1.332
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/package.json +1 -1
- package/payload/platform/lib/mcp-spawn-tee/dist/index.d.ts +24 -24
- package/payload/platform/lib/mcp-spawn-tee/dist/index.js +109 -75
- package/payload/platform/lib/mcp-spawn-tee/dist/index.js.map +1 -1
- package/payload/platform/lib/mcp-spawn-tee/src/__tests__/spawn-tee.test.ts +56 -19
- package/payload/platform/lib/mcp-spawn-tee/src/index.ts +112 -77
- package/payload/platform/neo4j/schema.cypher +58 -4
- package/payload/platform/plugins/admin/lib/mcp-spawn-tee/index.js +109 -75
- package/payload/platform/plugins/aeo/lib/mcp-spawn-tee/index.js +109 -75
- package/payload/platform/plugins/browser/lib/mcp-spawn-tee/index.js +109 -75
- package/payload/platform/plugins/contacts/lib/mcp-spawn-tee/index.js +109 -75
- package/payload/platform/plugins/contacts/mcp/dist/tools/__tests__/group-create.test.d.ts +2 -0
- package/payload/platform/plugins/contacts/mcp/dist/tools/__tests__/group-create.test.d.ts.map +1 -0
- package/payload/platform/plugins/contacts/mcp/dist/tools/__tests__/group-create.test.js +112 -0
- package/payload/platform/plugins/contacts/mcp/dist/tools/__tests__/group-create.test.js.map +1 -0
- package/payload/platform/plugins/contacts/mcp/dist/tools/__tests__/group-manage.test.d.ts +2 -0
- package/payload/platform/plugins/contacts/mcp/dist/tools/__tests__/group-manage.test.d.ts.map +1 -0
- package/payload/platform/plugins/contacts/mcp/dist/tools/__tests__/group-manage.test.js +102 -0
- package/payload/platform/plugins/contacts/mcp/dist/tools/__tests__/group-manage.test.js.map +1 -0
- package/payload/platform/plugins/contacts/mcp/dist/tools/group-create.d.ts.map +1 -1
- package/payload/platform/plugins/contacts/mcp/dist/tools/group-create.js +7 -2
- package/payload/platform/plugins/contacts/mcp/dist/tools/group-create.js.map +1 -1
- package/payload/platform/plugins/contacts/mcp/dist/tools/group-manage.d.ts.map +1 -1
- package/payload/platform/plugins/contacts/mcp/dist/tools/group-manage.js +5 -4
- package/payload/platform/plugins/contacts/mcp/dist/tools/group-manage.js.map +1 -1
- package/payload/platform/plugins/email/lib/mcp-spawn-tee/index.js +109 -75
- package/payload/platform/plugins/memory/lib/mcp-spawn-tee/index.js +109 -75
- package/payload/platform/plugins/memory/references/schema-estate-agent.md +17 -5
- package/payload/platform/plugins/outlook/lib/mcp-spawn-tee/index.js +109 -75
- package/payload/platform/plugins/quickbooks/lib/mcp-spawn-tee/index.js +109 -75
- package/payload/platform/plugins/replicate/lib/mcp-spawn-tee/index.js +109 -75
- package/payload/platform/plugins/scheduling/lib/mcp-spawn-tee/index.js +109 -75
- package/payload/platform/plugins/telegram/lib/mcp-spawn-tee/index.js +109 -75
- package/payload/platform/plugins/url-get/lib/mcp-spawn-tee/index.js +109 -75
- package/payload/platform/plugins/whatsapp/lib/mcp-spawn-tee/index.js +109 -75
- package/payload/platform/plugins/work/lib/mcp-spawn-tee/index.js +109 -75
- package/payload/platform/plugins/workflows/lib/mcp-spawn-tee/index.js +109 -75
- package/payload/platform/scripts/seed-neo4j.sh +18 -0
- package/payload/premium-plugins/writer-craft/lib/mcp-spawn-tee/index.js +109 -75
- package/payload/server/server.js +291 -213
|
@@ -1,47 +1,47 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
3
|
/**
|
|
4
|
-
* MCP spawn-tee —
|
|
4
|
+
* MCP spawn-tee — in-process stderr capture + lifecycle observability.
|
|
5
5
|
*
|
|
6
6
|
* Claude Code spawns each MCP server itself; the platform never holds a
|
|
7
|
-
* ChildProcess handle. This
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* is
|
|
7
|
+
* ChildProcess handle. This shim sits between Claude Code and the real MCP
|
|
8
|
+
* server: Claude Code runs `node <this> <real-entry>`, and the shim runs the
|
|
9
|
+
* real entry IN ITS OWN PROCESS via dynamic import() — one node runtime, not
|
|
10
|
+
* two. Before importing, it replaces process.stderr.write with a tee so every
|
|
11
|
+
* stderr byte the server writes is mirrored to the log sinks; stdin and stdout
|
|
12
|
+
* (the JSON-RPC channel) are never touched.
|
|
12
13
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
14
|
+
* Claude Code CLI → shim (this file) = node running <real-entry> in-process
|
|
15
|
+
* stdin/stdout : untouched (JSON-RPC channel)
|
|
16
|
+
* stderr : process.stderr.write teed → per-date + per-session + passthrough
|
|
16
17
|
*
|
|
17
|
-
*
|
|
18
|
-
* child stdin/stdout : inherited (Claude Code pipe, untouched)
|
|
19
|
-
* child stderr : piped → per-date log + per-session log + passthrough
|
|
20
|
-
*
|
|
21
|
-
* Destinations (Task 706):
|
|
18
|
+
* Destinations (Task 706) — unchanged:
|
|
22
19
|
* - `${LOG_DIR}/mcp-<name>-stderr-<date>.log` — per-date raw (back-compat;
|
|
23
20
|
* the in-process mcp-stderr-tee and the [mcp-init-error] probe read it).
|
|
24
21
|
* - `${LOG_DIR}/mcp-<name>-<SESSION_ID>.log` — per-session raw + lifecycle
|
|
25
|
-
* lines
|
|
26
|
-
*
|
|
27
|
-
* (enumeration spawn) — then the per-date file is the fallback.
|
|
22
|
+
* lines. Authoritative sink. Absent when SESSION_ID is unset (enumeration
|
|
23
|
+
* spawn) — then the per-date file is the fallback.
|
|
28
24
|
* - `server.log` via the loopback log-ingest route — best-effort mirror of
|
|
29
|
-
* the [mcp-helper] lifecycle lines.
|
|
30
|
-
* the per-session file already holds the line (written synchronously).
|
|
25
|
+
* the [mcp-helper] lifecycle lines.
|
|
31
26
|
*
|
|
32
|
-
* Lifecycle lines, correlation key `session=<id8> server=<name
|
|
27
|
+
* Lifecycle lines, correlation key `session=<id8> server=<name>` — unchanged:
|
|
33
28
|
* [mcp-helper] op=spawn ... pid= entry=
|
|
34
29
|
* [mcp-helper] op=boot ... head=<first stderr bytes>
|
|
35
|
-
* [mcp-helper] op=exit ... code= signal= lifetimeMs= stderr-tail=
|
|
30
|
+
* [mcp-helper] op=exit ... code= signal= lifetimeMs= stderr-tail=
|
|
31
|
+
*
|
|
32
|
+
* Process model (Task 989): the shim IS the server's process. op=exit fires
|
|
33
|
+
* from process.on("exit"), so it covers a normal exit, a non-zero exit, an
|
|
34
|
+
* uncaught throw (code 1), and a catchable-signal exit (SIGTERM/SIGINT/SIGHUP,
|
|
35
|
+
* whose handlers record the signal name). An external SIGKILL is uncatchable
|
|
36
|
+
* and leaves no op=exit line — the per-session stderr tail already on disk and
|
|
37
|
+
* Claude Code's own transport-drop are the evidence for that death mode.
|
|
36
38
|
*
|
|
37
|
-
* The
|
|
38
|
-
* SIGTERM/SIGINT are forwarded to the child so a Claude Code shutdown does
|
|
39
|
-
* not orphan it; the child exit code/signal is propagated verbatim.
|
|
39
|
+
* The shim never writes to fd 1 (stdout) — that is the JSON-RPC channel.
|
|
40
40
|
*/
|
|
41
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
const node_child_process_1 = require("node:child_process");
|
|
43
42
|
const node_fs_1 = require("node:fs");
|
|
44
43
|
const node_path_1 = require("node:path");
|
|
44
|
+
const node_url_1 = require("node:url");
|
|
45
45
|
const SERVER_NAME = process.env.MCP_SPAWN_TEE_NAME ?? "unknown";
|
|
46
46
|
const LOG_DIR = process.env.LOG_DIR;
|
|
47
47
|
const SESSION_ID = process.env.SESSION_ID;
|
|
@@ -49,24 +49,37 @@ const PLATFORM_PORT = process.env.PLATFORM_PORT;
|
|
|
49
49
|
const ENTRY = process.argv[2];
|
|
50
50
|
const SESSION_ID8 = SESSION_ID ? SESSION_ID.slice(0, 8) : "—";
|
|
51
51
|
const spawnStamp = Date.now();
|
|
52
|
-
// Per-session raw + lifecycle log (Task 706).
|
|
53
|
-
//
|
|
52
|
+
// Per-session raw + lifecycle log (Task 706). Empty SESSION_ID (enumeration
|
|
53
|
+
// spawn) → undefined, and the per-date file is the fallback.
|
|
54
54
|
const perSessionPath = LOG_DIR && SESSION_ID
|
|
55
55
|
? (0, node_path_1.resolve)(LOG_DIR, `mcp-${SERVER_NAME}-${SESSION_ID}.log`)
|
|
56
56
|
: undefined;
|
|
57
57
|
const perDatePath = LOG_DIR
|
|
58
58
|
? (0, node_path_1.resolve)(LOG_DIR, `mcp-${SERVER_NAME}-stderr-${new Date(spawnStamp).toISOString().slice(0, 10)}.log`)
|
|
59
59
|
: undefined;
|
|
60
|
-
// Rolling tail of
|
|
60
|
+
// Rolling tail of entry stderr for op=exit. Capped so a chatty server cannot
|
|
61
61
|
// grow the buffer without bound.
|
|
62
62
|
const TAIL_CAP = 2048;
|
|
63
63
|
let stderrTail = "";
|
|
64
64
|
let bootEmitted = false;
|
|
65
|
+
let exitEmitted = false;
|
|
66
|
+
let exitSignal;
|
|
67
|
+
// The real stderr writer, captured before the tee replaces it. Lifecycle lines
|
|
68
|
+
// and stderr passthrough both go through this so they are never re-teed into
|
|
69
|
+
// the per-date sink nor recursed back into the patched writer.
|
|
70
|
+
const rawStderrWrite = process.stderr.write.bind(process.stderr);
|
|
71
|
+
// LOG_DIR is created once, lazily, on the first successful append — not per
|
|
72
|
+
// chunk. teeWrite runs on the server's own stderr hot path now, so a per-call
|
|
73
|
+
// mkdirSync would be two syscalls per log line for nothing.
|
|
74
|
+
let logDirReady = false;
|
|
65
75
|
function appendSafe(path, data) {
|
|
66
76
|
if (!path || !LOG_DIR)
|
|
67
77
|
return;
|
|
68
78
|
try {
|
|
69
|
-
(
|
|
79
|
+
if (!logDirReady) {
|
|
80
|
+
(0, node_fs_1.mkdirSync)(LOG_DIR, { recursive: true });
|
|
81
|
+
logDirReady = true;
|
|
82
|
+
}
|
|
70
83
|
(0, node_fs_1.appendFileSync)(path, data);
|
|
71
84
|
}
|
|
72
85
|
catch {
|
|
@@ -74,15 +87,16 @@ function appendSafe(path, data) {
|
|
|
74
87
|
}
|
|
75
88
|
}
|
|
76
89
|
// Best-effort mirror of a lifecycle line to server.log via the loopback
|
|
77
|
-
// log-ingest route. Fire-and-forget: the per-session file is authoritative,
|
|
78
|
-
//
|
|
90
|
+
// log-ingest route. Fire-and-forget: the per-session file is authoritative, so
|
|
91
|
+
// a dropped POST loses nothing. On the "exit" event the loop is stopping, so
|
|
92
|
+
// the op=exit mirror may not flush — the per-session line, written sync, holds.
|
|
79
93
|
function postToServerLog(suffix, level) {
|
|
80
94
|
if (!PLATFORM_PORT)
|
|
81
95
|
return;
|
|
82
96
|
try {
|
|
83
97
|
const ctrl = new AbortController();
|
|
84
98
|
const t = setTimeout(() => ctrl.abort(), 500);
|
|
85
|
-
t.unref?.(); // never let the abort timer keep the
|
|
99
|
+
t.unref?.(); // never let the abort timer keep the shim's event loop alive
|
|
86
100
|
void fetch(`http://127.0.0.1:${PLATFORM_PORT}/api/admin/log-ingest`, {
|
|
87
101
|
method: "POST",
|
|
88
102
|
headers: { "content-type": "application/json" },
|
|
@@ -95,14 +109,15 @@ function postToServerLog(suffix, level) {
|
|
|
95
109
|
}
|
|
96
110
|
}
|
|
97
111
|
// Emit one [mcp-helper] lifecycle line: authoritative per-session file (sync,
|
|
98
|
-
// survives process.exit), the
|
|
99
|
-
// visibility), and a best-effort server.log mirror.
|
|
100
|
-
// after the tag and carries no newline (the
|
|
112
|
+
// survives process.exit), the shim's own stderr via the RAW writer (journald /
|
|
113
|
+
// Claude Code visibility, never re-teed), and a best-effort server.log mirror.
|
|
114
|
+
// `suffix` is the line body after the tag and carries no newline (the
|
|
115
|
+
// log-ingest route rejects newlines).
|
|
101
116
|
function emitLifecycle(suffix, level) {
|
|
102
117
|
const line = `[mcp-helper] ${suffix}\n`;
|
|
103
118
|
appendSafe(perSessionPath, line);
|
|
104
119
|
try {
|
|
105
|
-
|
|
120
|
+
rawStderrWrite(line);
|
|
106
121
|
}
|
|
107
122
|
catch { /* stderr closed */ }
|
|
108
123
|
postToServerLog(suffix, level);
|
|
@@ -111,49 +126,68 @@ if (!ENTRY) {
|
|
|
111
126
|
emitLifecycle(`op=error session=${SESSION_ID8} server=${SERVER_NAME} reason="no entry given (argv[2] missing)"`, "error");
|
|
112
127
|
process.exit(2);
|
|
113
128
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
129
|
+
// Replace process.stderr.write with a tee: mirror every server stderr byte to
|
|
130
|
+
// the per-date and per-session sinks, keep a rolling tail for op=exit, emit
|
|
131
|
+
// op=boot on the first bytes, then pass the write through to the real stderr.
|
|
132
|
+
const teeWrite = ((...args) => {
|
|
133
|
+
const chunk = args[0];
|
|
134
|
+
appendSafe(perDatePath, chunk); // per-date raw (back-compat)
|
|
135
|
+
appendSafe(perSessionPath, chunk); // per-session raw (Task 706)
|
|
136
|
+
const text = typeof chunk === "string" ? chunk : Buffer.from(chunk).toString("utf8");
|
|
137
|
+
stderrTail = (stderrTail + text).slice(-TAIL_CAP);
|
|
138
|
+
if (!bootEmitted) {
|
|
139
|
+
bootEmitted = true;
|
|
140
|
+
const head = text.split("\n")[0].slice(0, 200);
|
|
141
|
+
emitLifecycle(`op=boot session=${SESSION_ID8} server=${SERVER_NAME} head=${JSON.stringify(head)}`, "info");
|
|
142
|
+
}
|
|
143
|
+
return rawStderrWrite(...args); // passthrough
|
|
123
144
|
});
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
145
|
+
process.stderr.write = teeWrite;
|
|
146
|
+
// Catchable-signal handling. The shim drives the exit ONLY when it is the sole
|
|
147
|
+
// listener for the signal — i.e. the imported entry installed no handler of its
|
|
148
|
+
// own. In that case it records the signal (so op=exit carries signal=<sig>) and
|
|
149
|
+
// exits with 128+signum, mirroring the prior wrapper's exit-status convention.
|
|
150
|
+
//
|
|
151
|
+
// When the entry DID install a handler, the shim defers entirely and records
|
|
152
|
+
// nothing: the entry's handler decides the exit code, and op=exit reflects that
|
|
153
|
+
// exit verbatim. This matches the prior two-process model, where a child that
|
|
154
|
+
// caught the signal and exited cleanly was observed as code=0 signal=— (a clean
|
|
155
|
+
// self-exit), not as a signal death. Setting exitSignal here unconditionally
|
|
156
|
+
// would mislabel every graceful signal-driven shutdown as a signal kill.
|
|
157
|
+
function onSignal(sig, code) {
|
|
158
|
+
return () => {
|
|
159
|
+
if (process.listenerCount(sig) === 1) {
|
|
160
|
+
exitSignal = sig;
|
|
161
|
+
process.exit(code);
|
|
137
162
|
}
|
|
138
|
-
}
|
|
163
|
+
};
|
|
139
164
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
process.on("
|
|
143
|
-
process
|
|
144
|
-
//
|
|
145
|
-
//
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
165
|
+
process.on("SIGTERM", onSignal("SIGTERM", 143));
|
|
166
|
+
process.on("SIGINT", onSignal("SIGINT", 130));
|
|
167
|
+
process.on("SIGHUP", onSignal("SIGHUP", 129));
|
|
168
|
+
// op=exit, emitted once from the process "exit" event. Sync-only — the loop is
|
|
169
|
+
// stopping. When a catchable signal caused the exit, report code=— signal=<sig>
|
|
170
|
+
// to match the prior wrapper's format; otherwise code=<exit code> signal=—.
|
|
171
|
+
process.on("exit", (code) => {
|
|
172
|
+
if (exitEmitted)
|
|
173
|
+
return;
|
|
174
|
+
exitEmitted = true;
|
|
150
175
|
const lifetimeMs = Date.now() - spawnStamp;
|
|
151
176
|
const tail = stderrTail.slice(-200);
|
|
152
|
-
const
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
177
|
+
const codeField = exitSignal ? "—" : String(code);
|
|
178
|
+
const level = exitSignal || code !== 0 ? "error" : "info";
|
|
179
|
+
emitLifecycle(`op=exit session=${SESSION_ID8} server=${SERVER_NAME} pid=${process.pid} ` +
|
|
180
|
+
`code=${codeField} signal=${exitSignal ?? "—"} lifetimeMs=${lifetimeMs} stderr-tail=${JSON.stringify(tail)}`, level);
|
|
181
|
+
});
|
|
182
|
+
emitLifecycle(`op=spawn session=${SESSION_ID8} server=${SERVER_NAME} pid=${process.pid} entry=${ENTRY}`, "info");
|
|
183
|
+
// Run the real MCP server in THIS process. Dynamic import() (not top-level
|
|
184
|
+
// await — this file compiles to CommonJS) loads the ESM entry; a load-time
|
|
185
|
+
// failure mirrors the old child spawn-error path (op=error, exit 127). The
|
|
186
|
+
// op=exit handler is suppressed on this path so op=error stays the sole record.
|
|
187
|
+
import((0, node_url_1.pathToFileURL)(ENTRY).href).catch((err) => {
|
|
188
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
189
|
+
exitEmitted = true;
|
|
190
|
+
emitLifecycle(`op=error session=${SESSION_ID8} server=${SERVER_NAME} reason=${JSON.stringify(`import error: ${msg}`)}`, "error");
|
|
191
|
+
process.exit(127);
|
|
158
192
|
});
|
|
159
193
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"group-create.test.d.ts","sourceRoot":"","sources":["../../../src/tools/__tests__/group-create.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
// Task 988 — group-create resolves a participant by name. The old predicate
|
|
2
|
+
// composed the display name with `p.givenName + COALESCE(' ' + p.familyName,
|
|
3
|
+
// '')`, which is null in Cypher whenever givenName is null, so a familyName-only
|
|
4
|
+
// Person could never be matched by name. These tests lock the null-safe,
|
|
5
|
+
// case-insensitive composed-display-name equality (parity with
|
|
6
|
+
// memory-lookup-by-name's Person branch) and the query-whitespace normalization.
|
|
7
|
+
// Live Neo4j matching is exercised on the Pi; predicate correctness is locked here.
|
|
8
|
+
import { describe, it, expect, beforeEach, vi } from "vitest";
|
|
9
|
+
const mockSession = {
|
|
10
|
+
run: vi.fn(),
|
|
11
|
+
executeWrite: vi.fn(),
|
|
12
|
+
close: vi.fn().mockResolvedValue(undefined),
|
|
13
|
+
};
|
|
14
|
+
vi.mock("../../lib/neo4j.js", () => ({
|
|
15
|
+
getSession: () => mockSession,
|
|
16
|
+
}));
|
|
17
|
+
vi.mock("../../../../../../lib/graph-trash/dist/index.js", () => ({
|
|
18
|
+
notTrashed: (alias) => `(NOT ${alias}:Trashed)`,
|
|
19
|
+
}));
|
|
20
|
+
vi.mock("../../../../../../lib/graph-write/dist/index.js", () => ({
|
|
21
|
+
stampCreatedBy: (props) => props,
|
|
22
|
+
}));
|
|
23
|
+
import { groupCreate } from "../group-create.js";
|
|
24
|
+
const ACCOUNT_ID = "20028fb5-db26-4de7-bff6-c5ec2d4fc766";
|
|
25
|
+
const COMPOSED_PREDICATE = "toLower(trim(coalesce(p.givenName, '') + ' ' + coalesce(p.familyName, ''))) = toLower($identifier)";
|
|
26
|
+
// elementId + p.givenName record shape returned by the participant-resolve query.
|
|
27
|
+
function resolveRecord(id, name) {
|
|
28
|
+
return { get: (k) => (k === "id" ? id : name) };
|
|
29
|
+
}
|
|
30
|
+
function countRecord(value) {
|
|
31
|
+
return { get: () => ({ toNumber: () => value }) };
|
|
32
|
+
}
|
|
33
|
+
// Resolve every participant to a distinct person; the slug check is unique, the
|
|
34
|
+
// write is a no-op, and the brand lookup returns nothing (default base URL).
|
|
35
|
+
function wireHappyPath() {
|
|
36
|
+
let person = 0;
|
|
37
|
+
mockSession.run.mockImplementation((cypher) => {
|
|
38
|
+
if (cypher.includes("count(c) AS cnt")) {
|
|
39
|
+
return Promise.resolve({ records: [countRecord(0)] });
|
|
40
|
+
}
|
|
41
|
+
if (cypher.includes("p:Person")) {
|
|
42
|
+
person += 1;
|
|
43
|
+
return Promise.resolve({
|
|
44
|
+
records: [resolveRecord(`4:person:${person}`, person === 1 ? null : "Jane")],
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
return Promise.resolve({ records: [] }); // LocalBusiness brand lookup
|
|
48
|
+
});
|
|
49
|
+
mockSession.executeWrite.mockImplementation(async (cb) => cb({ run: vi.fn().mockResolvedValue({ records: [] }) }));
|
|
50
|
+
}
|
|
51
|
+
function participantResolveCalls() {
|
|
52
|
+
return mockSession.run.mock.calls.filter(([cypher]) => cypher.includes("p:Person"));
|
|
53
|
+
}
|
|
54
|
+
beforeEach(() => {
|
|
55
|
+
mockSession.run.mockReset();
|
|
56
|
+
mockSession.executeWrite.mockReset();
|
|
57
|
+
mockSession.close.mockClear();
|
|
58
|
+
});
|
|
59
|
+
describe("group-create — composed by-name participant match (Task 988)", () => {
|
|
60
|
+
it("matches participants on the null-safe composed display name", async () => {
|
|
61
|
+
wireHappyPath();
|
|
62
|
+
await groupCreate({
|
|
63
|
+
groupName: "Smiths",
|
|
64
|
+
agentSlug: "default",
|
|
65
|
+
participants: ["Smith", "Jane Smith"],
|
|
66
|
+
accountId: ACCOUNT_ID,
|
|
67
|
+
createdBy: {},
|
|
68
|
+
});
|
|
69
|
+
const [cypher] = participantResolveCalls()[0];
|
|
70
|
+
expect(cypher).toContain(COMPOSED_PREDICATE);
|
|
71
|
+
// The old non-null-safe composition must be gone.
|
|
72
|
+
expect(cypher).not.toContain("p.givenName + COALESCE");
|
|
73
|
+
});
|
|
74
|
+
it("resolves a familyName-only participant rather than dropping it as not-found", async () => {
|
|
75
|
+
wireHappyPath();
|
|
76
|
+
const result = await groupCreate({
|
|
77
|
+
groupName: "Smiths",
|
|
78
|
+
agentSlug: "default",
|
|
79
|
+
participants: ["Smith", "Jane Smith"],
|
|
80
|
+
accountId: ACCOUNT_ID,
|
|
81
|
+
createdBy: {},
|
|
82
|
+
});
|
|
83
|
+
expect(result.notFound).toEqual([]);
|
|
84
|
+
});
|
|
85
|
+
it("normalizes the threaded participant query whitespace", async () => {
|
|
86
|
+
wireHappyPath();
|
|
87
|
+
await groupCreate({
|
|
88
|
+
groupName: "Smiths",
|
|
89
|
+
agentSlug: "default",
|
|
90
|
+
participants: [" Jane Smith ", "Smith"],
|
|
91
|
+
accountId: ACCOUNT_ID,
|
|
92
|
+
createdBy: {},
|
|
93
|
+
});
|
|
94
|
+
const [, params] = participantResolveCalls()[0];
|
|
95
|
+
expect(params.identifier).toBe("Jane Smith");
|
|
96
|
+
});
|
|
97
|
+
it("reports the original identifier (not the normalized form) when nothing resolves", async () => {
|
|
98
|
+
mockSession.run.mockImplementation((cypher) => {
|
|
99
|
+
if (cypher.includes("count(c) AS cnt"))
|
|
100
|
+
return Promise.resolve({ records: [countRecord(0)] });
|
|
101
|
+
return Promise.resolve({ records: [] }); // no participant resolves
|
|
102
|
+
});
|
|
103
|
+
await expect(groupCreate({
|
|
104
|
+
groupName: "Smiths",
|
|
105
|
+
agentSlug: "default",
|
|
106
|
+
participants: [" Nobody Here ", "Ghost"],
|
|
107
|
+
accountId: ACCOUNT_ID,
|
|
108
|
+
createdBy: {},
|
|
109
|
+
})).rejects.toThrow("Nobody Here");
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
//# sourceMappingURL=group-create.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"group-create.test.js","sourceRoot":"","sources":["../../../src/tools/__tests__/group-create.test.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,6EAA6E;AAC7E,iFAAiF;AACjF,yEAAyE;AACzE,+DAA+D;AAC/D,iFAAiF;AACjF,oFAAoF;AAEpF,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAE9D,MAAM,WAAW,GAAG;IAClB,GAAG,EAAE,EAAE,CAAC,EAAE,EAAE;IACZ,YAAY,EAAE,EAAE,CAAC,EAAE,EAAE;IACrB,KAAK,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,SAAS,CAAC;CAC5C,CAAC;AAEF,EAAE,CAAC,IAAI,CAAC,oBAAoB,EAAE,GAAG,EAAE,CAAC,CAAC;IACnC,UAAU,EAAE,GAAG,EAAE,CAAC,WAAW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/F,WAAW,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC,MAAc,EAAE,EAAE;YACpD,IAAI,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAAC;gBAAE,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;YAC9F,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,0BAA0B;QACrE,CAAC,CAAC,CAAC;QAEH,MAAM,MAAM,CACV,WAAW,CAAC;YACV,SAAS,EAAE,QAAQ;YACnB,SAAS,EAAE,SAAS;YACpB,YAAY,EAAE,CAAC,gBAAgB,EAAE,OAAO,CAAC;YACzC,SAAS,EAAE,UAAU;YACrB,SAAS,EAAE,EAAW;SACvB,CAAC,CACH,CAAC,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;IACnC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"group-manage.test.d.ts","sourceRoot":"","sources":["../../../src/tools/__tests__/group-manage.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// Task 988 — group-manage adds and removes a participant by name. Both the add
|
|
2
|
+
// and remove queries composed the display name with `p.givenName + COALESCE(' '
|
|
3
|
+
// + p.familyName, '')`, which is null whenever givenName is null, so a
|
|
4
|
+
// familyName-only Person could be neither added to nor removed from a group by
|
|
5
|
+
// name. These tests lock the null-safe, case-insensitive composed-display-name
|
|
6
|
+
// equality (parity with memory-lookup-by-name's Person branch) and the
|
|
7
|
+
// query-whitespace normalization. Live Neo4j matching is exercised on the Pi.
|
|
8
|
+
import { describe, it, expect, beforeEach, vi } from "vitest";
|
|
9
|
+
const mockSession = {
|
|
10
|
+
run: vi.fn(),
|
|
11
|
+
close: vi.fn().mockResolvedValue(undefined),
|
|
12
|
+
};
|
|
13
|
+
vi.mock("../../lib/neo4j.js", () => ({
|
|
14
|
+
getSession: () => mockSession,
|
|
15
|
+
}));
|
|
16
|
+
vi.mock("../../../../../../lib/graph-trash/dist/index.js", () => ({
|
|
17
|
+
notTrashed: (alias) => `(NOT ${alias}:Trashed)`,
|
|
18
|
+
}));
|
|
19
|
+
import { groupManage } from "../group-manage.js";
|
|
20
|
+
const ACCOUNT_ID = "20028fb5-db26-4de7-bff6-c5ec2d4fc766";
|
|
21
|
+
const GROUP_SLUG = "smiths";
|
|
22
|
+
const COMPOSED_PREDICATE = "toLower(trim(coalesce(p.givenName, '') + ' ' + coalesce(p.familyName, ''))) = toLower($participant)";
|
|
23
|
+
function record(values) {
|
|
24
|
+
return { get: (k) => values[k] };
|
|
25
|
+
}
|
|
26
|
+
function countRecord(value) {
|
|
27
|
+
return { get: () => ({ toNumber: () => value }) };
|
|
28
|
+
}
|
|
29
|
+
// Group lookup succeeds; add returns a resolved name; remove deletes one edge;
|
|
30
|
+
// the trailing participant list is empty (irrelevant to these predicate locks).
|
|
31
|
+
function wire({ removed = 1 } = {}) {
|
|
32
|
+
mockSession.run.mockImplementation((cypher) => {
|
|
33
|
+
if (cypher.includes("groupSlug: $groupSlug")) {
|
|
34
|
+
return Promise.resolve({ records: [record({ sessionId: "sess-1", groupName: "Smiths" })] });
|
|
35
|
+
}
|
|
36
|
+
if (cypher.includes("MERGE (p)-[r:PARTICIPATES_IN")) {
|
|
37
|
+
return Promise.resolve({ records: [record({ name: "Smith" })] });
|
|
38
|
+
}
|
|
39
|
+
if (cypher.includes("DELETE r")) {
|
|
40
|
+
return Promise.resolve({ records: [countRecord(removed)] });
|
|
41
|
+
}
|
|
42
|
+
return Promise.resolve({ records: [] }); // trailing participant list
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
function callContaining(fragment) {
|
|
46
|
+
return mockSession.run.mock.calls.find(([cypher]) => cypher.includes(fragment));
|
|
47
|
+
}
|
|
48
|
+
beforeEach(() => {
|
|
49
|
+
mockSession.run.mockReset();
|
|
50
|
+
mockSession.close.mockClear();
|
|
51
|
+
});
|
|
52
|
+
describe("group-manage add — composed by-name match (Task 988)", () => {
|
|
53
|
+
it("matches the participant on the null-safe composed display name", async () => {
|
|
54
|
+
wire();
|
|
55
|
+
await groupManage({
|
|
56
|
+
groupSlug: GROUP_SLUG,
|
|
57
|
+
action: "add",
|
|
58
|
+
participant: "Smith",
|
|
59
|
+
accountId: ACCOUNT_ID,
|
|
60
|
+
});
|
|
61
|
+
const [cypher] = callContaining("MERGE (p)-[r:PARTICIPATES_IN");
|
|
62
|
+
expect(cypher).toContain(COMPOSED_PREDICATE);
|
|
63
|
+
expect(cypher).not.toContain("p.givenName + COALESCE");
|
|
64
|
+
});
|
|
65
|
+
it("normalizes the threaded participant query whitespace", async () => {
|
|
66
|
+
wire();
|
|
67
|
+
await groupManage({
|
|
68
|
+
groupSlug: GROUP_SLUG,
|
|
69
|
+
action: "add",
|
|
70
|
+
participant: " Jane Smith ",
|
|
71
|
+
accountId: ACCOUNT_ID,
|
|
72
|
+
});
|
|
73
|
+
const [, params] = callContaining("MERGE (p)-[r:PARTICIPATES_IN");
|
|
74
|
+
expect(params.participant).toBe("Jane Smith");
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
describe("group-manage remove — composed by-name match (Task 988)", () => {
|
|
78
|
+
it("matches the participant on the null-safe composed display name", async () => {
|
|
79
|
+
wire();
|
|
80
|
+
await groupManage({
|
|
81
|
+
groupSlug: GROUP_SLUG,
|
|
82
|
+
action: "remove",
|
|
83
|
+
participant: "Smith",
|
|
84
|
+
accountId: ACCOUNT_ID,
|
|
85
|
+
});
|
|
86
|
+
const [cypher] = callContaining("DELETE r");
|
|
87
|
+
expect(cypher).toContain(COMPOSED_PREDICATE);
|
|
88
|
+
expect(cypher).not.toContain("p.givenName + COALESCE");
|
|
89
|
+
});
|
|
90
|
+
it("normalizes the threaded participant query whitespace", async () => {
|
|
91
|
+
wire();
|
|
92
|
+
await groupManage({
|
|
93
|
+
groupSlug: GROUP_SLUG,
|
|
94
|
+
action: "remove",
|
|
95
|
+
participant: " Jane Smith ",
|
|
96
|
+
accountId: ACCOUNT_ID,
|
|
97
|
+
});
|
|
98
|
+
const [, params] = callContaining("DELETE r");
|
|
99
|
+
expect(params.participant).toBe("Jane Smith");
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
//# sourceMappingURL=group-manage.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"group-manage.test.js","sourceRoot":"","sources":["../../../src/tools/__tests__/group-manage.test.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,gFAAgF;AAChF,uEAAuE;AACvE,+EAA+E;AAC/E,+EAA+E;AAC/E,uEAAuE;AACvE,8EAA8E;AAE9E,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAE9D,MAAM,WAAW,GAAG;IAClB,GAAG,EAAE,EAAE,CAAC,EAAE,EAAE;IACZ,KAAK,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,SAAS,CAAC;CAC5C,CAAC;AAEF,EAAE,CAAC,IAAI,CAAC,oBAAoB,EAAE,GAAG,EAAE,CAAC,CAAC;IACnC,UAAU,EAAE,GAAG,EAAE,CAAC,WAAW;CAC9B,CAAC,CAAC,CAAC;AAEJ,EAAE,CAAC,IAAI,CAAC,iDAAiD,EAAE,GAAG,EAAE,CAAC,CAAC;IAChE,UAAU,EAAE,CAAC,KAAa,EAAE,EAAE,CAAC,QAAQ,KAAK,WAAW;CACxD,CAAC,CAAC,CAAC;AAEJ,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,MAAM,UAAU,GAAG,sCAAsC,CAAC;AAC1D,MAAM,UAAU,GAAG,QAAQ,CAAC;AAE5B,MAAM,kBAAkB,GACtB,qGAAqG,CAAC;A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AAC;AACL,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,yDAAyD,EAAE,GAAG,EAAE;IACvE,EAAE,CAAC,gEAAgE,EAAE,KAAK,IAAI,EAAE;QAC9E,IAAI,EAAE,CAAC;QAEP,MAAM,WAAW,CAAC;YAChB,SAAS,EAAE,UAAU;YACrB,MAAM,EAAE,QAAQ;YAChB,WAAW,EAAE,OAAO;YACpB,SAAS,EAAE,UAAU;SACtB,CAAC,CAAC;QAEH,MAAM,CAAC,MAAM,CAAC,GAAG,cAAc,CAAC,UAAU,CAAC,CAAC;QAC5C,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,kBAAkB,CAAC,CAAC;QAC7C,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,wBAAwB,CAAC,CAAC;IACzD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,sDAAsD,EAAE,KAAK,IAAI,EAAE;QACpE,IAAI,EAAE,CAAC;QAEP,MAAM,WAAW,CAAC;YAChB,SAAS,EAAE,UAAU;YACrB,MAAM,EAAE,QAAQ;YAChB,WAAW,EAAE,iBAAiB;YAC9B,SAAS,EAAE,UAAU;SACtB,CAAC,CAAC;QAEH,MAAM,CAAC,EAAE,MAAM,CAAC,GAAG,cAAc,CAAC,UAAU,CAAC,CAAC;QAC9C,MAAM,CAAE,MAAkC,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IAC7E,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"group-create.d.ts","sourceRoot":"","sources":["../../src/tools/group-create.ts"],"names":[],"mappings":"AAGA,OAAO,EAAkB,KAAK,SAAS,EAAE,MAAM,8CAA8C,CAAC;
|
|
1
|
+
{"version":3,"file":"group-create.d.ts","sourceRoot":"","sources":["../../src/tools/group-create.ts"],"names":[],"mappings":"AAGA,OAAO,EAAkB,KAAK,SAAS,EAAE,MAAM,8CAA8C,CAAC;AAY9F,UAAU,iBAAiB;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,SAAS,CAAC;CACtB;AAED,UAAU,iBAAiB;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,wBAAsB,WAAW,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAiHvF"}
|
|
@@ -2,6 +2,7 @@ import { randomUUID } from "node:crypto";
|
|
|
2
2
|
import { getSession } from "../lib/neo4j.js";
|
|
3
3
|
import { notTrashed } from "../../../../../lib/graph-trash/dist/index.js";
|
|
4
4
|
import { stampCreatedBy } from "../../../../../lib/graph-write/dist/index.js";
|
|
5
|
+
import { normalizeNameQuery } from "./contact-lookup.js";
|
|
5
6
|
function generateGroupSlug(name) {
|
|
6
7
|
const base = name
|
|
7
8
|
.toLowerCase()
|
|
@@ -36,12 +37,16 @@ export async function groupCreate(params) {
|
|
|
36
37
|
const resolvedParticipants = [];
|
|
37
38
|
const notFound = [];
|
|
38
39
|
for (const identifier of participants) {
|
|
40
|
+
// Match the read-time-composed display name (null-safe, case-insensitive)
|
|
41
|
+
// so a familyName-only Person resolves by name, exactly as the lookup
|
|
42
|
+
// tools do; the original identifier is still reported in notFound. The
|
|
43
|
+
// email/telephone branches keep their existing exact match.
|
|
39
44
|
const r = await session.run(`MATCH (p:Person {accountId: $accountId})
|
|
40
|
-
WHERE (p.givenName +
|
|
45
|
+
WHERE (toLower(trim(coalesce(p.givenName, '') + ' ' + coalesce(p.familyName, ''))) = toLower($identifier)
|
|
41
46
|
OR p.email = $identifier
|
|
42
47
|
OR p.telephone = $identifier)
|
|
43
48
|
AND ${notTrashed("p")}
|
|
44
|
-
RETURN elementId(p) AS id, p.givenName AS name LIMIT 1`, { accountId, identifier });
|
|
49
|
+
RETURN elementId(p) AS id, p.givenName AS name LIMIT 1`, { accountId, identifier: normalizeNameQuery(identifier) });
|
|
45
50
|
if (r.records.length > 0) {
|
|
46
51
|
resolvedParticipants.push({
|
|
47
52
|
identifier,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"group-create.js","sourceRoot":"","sources":["../../src/tools/group-create.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,8CAA8C,CAAC;AAC1E,OAAO,EAAE,cAAc,EAAkB,MAAM,8CAA8C,CAAC;
|
|
1
|
+
{"version":3,"file":"group-create.js","sourceRoot":"","sources":["../../src/tools/group-create.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,8CAA8C,CAAC;AAC1E,OAAO,EAAE,cAAc,EAAkB,MAAM,8CAA8C,CAAC;AAC9F,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAEzD,SAAS,iBAAiB,CAAC,IAAY;IACrC,MAAM,IAAI,GAAG,IAAI;SACd,WAAW,EAAE;SACb,OAAO,CAAC,aAAa,EAAE,GAAG,CAAC;SAC3B,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC;SACrB,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAChB,OAAO,IAAI,IAAI,OAAO,CAAC;AACzB,CAAC;AAkBD,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,MAAyB;IACzD,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AAC,CAAC,SAAS,CAAC,CAAC;QAE5D,MAAM,WAAW,GAAG,MAAM,OAAO,CAAC,GAAG,CACnC;qCAC+B,EAC/B,EAAE,SAAS,EAAE,CACd,CAAC;QACF,MAAM,QAAQ,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,UAAU,CAAuB,CAAC;QAC/E,MAAM,OAAO,GAAG,QAAQ,CAAC,CAAC,CAAC,WAAW,QAAQ,EAAE,CAAC,CAAC,CAAC,kBAAkB,CAAC;QACtE,MAAM,YAAY,GAAG,GAAG,OAAO,MAAM,SAAS,EAAE,CAAC;QAEjD,OAAO,CAAC,KAAK,CACX,sBAAsB,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,UAAU,SAAS,iBAAiB,MAAM,CAAC,MAAM,GAAG,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,aAAa,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAC3J,CAAC;QAEF,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,CAAC;IAClE,CAAC;YAAS,CAAC;QACT,MAAM,OAAO,CAAC,KAAK,EAAE,CAAC;IACxB,CAAC;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"group-manage.d.ts","sourceRoot":"","sources":["../../src/tools/group-manage.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"group-manage.d.ts","sourceRoot":"","sources":["../../src/tools/group-manage.ts"],"names":[],"mappings":"AAIA,UAAU,iBAAiB;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAC;IAClC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,UAAU,iBAAiB;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,EAAE,CAAC;CACxB;AAED,wBAAsB,WAAW,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CA2FvF"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { getSession } from "../lib/neo4j.js";
|
|
2
2
|
import { notTrashed } from "../../../../../lib/graph-trash/dist/index.js";
|
|
3
|
+
import { normalizeNameQuery } from "./contact-lookup.js";
|
|
3
4
|
export async function groupManage(params) {
|
|
4
5
|
const { groupSlug, action, participant, accountId } = params;
|
|
5
6
|
const session = getSession();
|
|
@@ -18,7 +19,7 @@ export async function groupManage(params) {
|
|
|
18
19
|
if (!participant)
|
|
19
20
|
throw new Error("participant is required for add action");
|
|
20
21
|
const addResult = await session.run(`MATCH (p:Person {accountId: $accountId})
|
|
21
|
-
WHERE (p.givenName +
|
|
22
|
+
WHERE (toLower(trim(coalesce(p.givenName, '') + ' ' + coalesce(p.familyName, ''))) = toLower($participant)
|
|
22
23
|
OR p.email = $participant
|
|
23
24
|
OR p.telephone = $participant)
|
|
24
25
|
AND ${notTrashed("p")}
|
|
@@ -26,7 +27,7 @@ export async function groupManage(params) {
|
|
|
26
27
|
MATCH (c:Conversation {sessionId: $sessionId})
|
|
27
28
|
MERGE (p)-[r:PARTICIPATES_IN]->(c)
|
|
28
29
|
ON CREATE SET r.joinedAt = datetime(), r.displayName = p.givenName
|
|
29
|
-
RETURN p.givenName AS name`, { accountId, participant, sessionId });
|
|
30
|
+
RETURN p.givenName AS name`, { accountId, participant: normalizeNameQuery(participant), sessionId });
|
|
30
31
|
const name = addResult.records[0]?.get("name");
|
|
31
32
|
if (!name) {
|
|
32
33
|
throw new Error(`Contact not found: ${participant}`);
|
|
@@ -37,12 +38,12 @@ export async function groupManage(params) {
|
|
|
37
38
|
if (!participant)
|
|
38
39
|
throw new Error("participant is required for remove action");
|
|
39
40
|
const removeResult = await session.run(`MATCH (p:Person {accountId: $accountId})-[r:PARTICIPATES_IN]->(c:Conversation {sessionId: $sessionId})
|
|
40
|
-
WHERE (p.givenName +
|
|
41
|
+
WHERE (toLower(trim(coalesce(p.givenName, '') + ' ' + coalesce(p.familyName, ''))) = toLower($participant)
|
|
41
42
|
OR p.email = $participant
|
|
42
43
|
OR p.telephone = $participant)
|
|
43
44
|
AND ${notTrashed("p")}
|
|
44
45
|
DELETE r
|
|
45
|
-
RETURN count(r) AS removed`, { accountId, participant, sessionId });
|
|
46
|
+
RETURN count(r) AS removed`, { accountId, participant: normalizeNameQuery(participant), sessionId });
|
|
46
47
|
const removed = removeResult.records[0]?.get("removed")?.toNumber?.() ?? 0;
|
|
47
48
|
if (removed === 0) {
|
|
48
49
|
throw new Error(`Participant not found in group: ${participant}`);
|