conduyt 1.48.0 → 1.49.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 +148 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2440,6 +2440,154 @@ async function patchGeneralSettings(client, body) {
|
|
|
2440
2440
|
throw err;
|
|
2441
2441
|
}
|
|
2442
2442
|
}
|
|
2443
|
+
function poolFilterOf(settings) {
|
|
2444
|
+
const raw = settings.poolFilter;
|
|
2445
|
+
const r = raw && typeof raw === "object" && !Array.isArray(raw) ? raw : {};
|
|
2446
|
+
const int = (v) => (typeof v === "number" && Number.isInteger(v) ? v : null);
|
|
2447
|
+
const min = int(r.minScore);
|
|
2448
|
+
return {
|
|
2449
|
+
enabled: r.enabled === true,
|
|
2450
|
+
tagIds: Array.isArray(r.tagIds) ? r.tagIds.filter((t) => typeof t === "string") : [],
|
|
2451
|
+
sources: Array.isArray(r.sources) ? r.sources.filter((x) => typeof x === "string") : [],
|
|
2452
|
+
minScore: min !== null && min > 0 ? min : null,
|
|
2453
|
+
maxScore: int(r.maxScore),
|
|
2454
|
+
createdWithinDays: int(r.createdWithinDays),
|
|
2455
|
+
};
|
|
2456
|
+
}
|
|
2457
|
+
function poolCriteriaPhrases(f, tags, tagLookupFailed = false) {
|
|
2458
|
+
if (!f.enabled)
|
|
2459
|
+
return [];
|
|
2460
|
+
const list = (items) => (items.length <= 1 ? items.join("") : `${items.slice(0, -1).join(", ")} or ${items[items.length - 1]}`);
|
|
2461
|
+
const out = [];
|
|
2462
|
+
if (f.sources.length > 0)
|
|
2463
|
+
out.push(`from ${list(f.sources)}`);
|
|
2464
|
+
if (f.createdWithinDays !== null)
|
|
2465
|
+
out.push(f.createdWithinDays === 1 ? "added in the past day" : `added in the past ${f.createdWithinDays} days`);
|
|
2466
|
+
if (tags.length > 0) {
|
|
2467
|
+
if (tagLookupFailed)
|
|
2468
|
+
out.push(`tagged one of ${tags.length} ${tags.length === 1 ? "tag" : "tags"} (names unavailable right now)`);
|
|
2469
|
+
else {
|
|
2470
|
+
const names = tags.filter((t) => t.name !== null).map((t) => t.name);
|
|
2471
|
+
const deleted = tags.length - names.length;
|
|
2472
|
+
if (deleted > 0)
|
|
2473
|
+
names.push(deleted === 1 ? "a deleted tag (matches nothing)" : `${deleted} deleted tags (match nothing)`);
|
|
2474
|
+
out.push(`tagged ${list(names)}`);
|
|
2475
|
+
}
|
|
2476
|
+
}
|
|
2477
|
+
if (f.minScore !== null && f.maxScore !== null)
|
|
2478
|
+
out.push(f.minScore === f.maxScore ? `lead score ${f.minScore}` : `lead score ${f.minScore} to ${f.maxScore}`);
|
|
2479
|
+
else if (f.minScore !== null)
|
|
2480
|
+
out.push(`lead score ${f.minScore} or higher`);
|
|
2481
|
+
else if (f.maxScore !== null)
|
|
2482
|
+
out.push(`lead score ${f.maxScore} or lower`);
|
|
2483
|
+
return out;
|
|
2484
|
+
}
|
|
2485
|
+
/** a flag's whole number in [min, max], or null for the literal "none" (clears the bound) */
|
|
2486
|
+
function boundedIntFlag(raw, flag, min, max) {
|
|
2487
|
+
if (raw === undefined)
|
|
2488
|
+
return undefined;
|
|
2489
|
+
if (raw.trim().toLowerCase() === "none")
|
|
2490
|
+
return null;
|
|
2491
|
+
if (!/^\d+$/.test(raw.trim()))
|
|
2492
|
+
throw new Error(`${flag} must be a whole number between ${min} and ${max}, or "none"`);
|
|
2493
|
+
const n = Number(raw.trim());
|
|
2494
|
+
if (n < min || n > max)
|
|
2495
|
+
throw new Error(`${flag} must be between ${min} and ${max}`);
|
|
2496
|
+
return n;
|
|
2497
|
+
}
|
|
2498
|
+
/** "a, b" → ["a","b"]; the literal "none" → [] (clears the rule) */
|
|
2499
|
+
function listFlag(raw) {
|
|
2500
|
+
if (raw === undefined)
|
|
2501
|
+
return undefined;
|
|
2502
|
+
if (raw.trim().toLowerCase() === "none")
|
|
2503
|
+
return [];
|
|
2504
|
+
return raw.split(",").map((x) => x.trim()).filter(Boolean);
|
|
2505
|
+
}
|
|
2506
|
+
const leadPool = program
|
|
2507
|
+
.command("lead-pool")
|
|
2508
|
+
.description("Lead pool curation behind Up for Grabs / Lead Pool: which unassigned leads agents can see and claim (settings scope)");
|
|
2509
|
+
leadPool
|
|
2510
|
+
.command("settings")
|
|
2511
|
+
.description("Show the curated pool rules (settings.poolFilter): enabled, tags (any of, with names), sources (any of), minScore / maxScore (lead score floor / ceiling; equal = one exact score), createdWithinDays (added to the CRM in the past N days — creation time), the plain-English criteria line the Up for Grabs page shows, and poolClaimDailyLimit. Every configured rule must match; an empty rule is skipped.")
|
|
2512
|
+
.action(run(async (client) => {
|
|
2513
|
+
const result = (await client.get("/api/v1/settings"));
|
|
2514
|
+
const raw = result?.data ?? {};
|
|
2515
|
+
const filter = poolFilterOf(raw);
|
|
2516
|
+
let tags = [];
|
|
2517
|
+
let tagLookupFailed = false;
|
|
2518
|
+
if (filter.tagIds.length > 0) {
|
|
2519
|
+
try {
|
|
2520
|
+
const t = (await client.get("/api/v1/tags?per_page=200"));
|
|
2521
|
+
const rows = Array.isArray(t) ? t : Array.isArray(t.data) ? (t.data) : [];
|
|
2522
|
+
const byId = new Map(rows.filter((x) => !!x && typeof x === "object" && typeof x.id === "string").map((x) => [x.id, x.name]));
|
|
2523
|
+
tags = filter.tagIds.map((id) => ({ id, name: byId.get(id) ?? null }));
|
|
2524
|
+
}
|
|
2525
|
+
catch {
|
|
2526
|
+
tagLookupFailed = true;
|
|
2527
|
+
tags = filter.tagIds.map((id) => ({ id, name: null }));
|
|
2528
|
+
}
|
|
2529
|
+
}
|
|
2530
|
+
const limit = typeof raw.poolClaimDailyLimit === "number" ? raw.poolClaimDailyLimit : null;
|
|
2531
|
+
return { data: { ...filter, tags, ...(tagLookupFailed ? { tagLookupFailed } : {}), criteria: poolCriteriaPhrases(filter, tags, tagLookupFailed), poolClaimDailyLimit: limit } };
|
|
2532
|
+
}));
|
|
2533
|
+
leadPool
|
|
2534
|
+
.command("set-settings")
|
|
2535
|
+
.description("Change the curated pool rules. Pass only what changes; the rest keep their stored value. --enabled on|off; --tags <uuid,uuid|none> (lead must carry ANY of these; none clears); --sources <a,b|none> (lead source is ANY of these, exact; none clears); --min-score <0-1000|none>; --max-score <0-1000|none> (equal to --min-score = one exact score, e.g. lead quality 4); --added-within-days <1-365|none> (only leads added to the CRM in the past N days — creation time; a re-import of an existing contact is not new); --claim-limit <0-200> (daily grabs per agent, 0 = no cap). Enabling with no rule at all is refused; a max below the min is refused. Sends the settings revision it read (409 = another save landed first: re-run).")
|
|
2536
|
+
.option("--enabled <on|off>", "turn the curated pool on or off")
|
|
2537
|
+
.option("--tags <ids>", "comma-separated tag UUIDs (any of), or none")
|
|
2538
|
+
.option("--sources <names>", "comma-separated lead sources (any of), or none")
|
|
2539
|
+
.option("--min-score <n>", "lead score floor 0-1000, or none")
|
|
2540
|
+
.option("--max-score <n>", "lead score ceiling 0-1000, or none")
|
|
2541
|
+
.option("--added-within-days <n>", "only leads added to the CRM in the past 1-365 days, or none")
|
|
2542
|
+
.option("--claim-limit <n>", "daily claim cap per agent 0-200 (0 = off)")
|
|
2543
|
+
.action(run(async (client, opts) => {
|
|
2544
|
+
const current = (await client.get("/api/v1/settings"));
|
|
2545
|
+
const stored = poolFilterOf(current?.data ?? {});
|
|
2546
|
+
const tagIds = listFlag(opts.tags);
|
|
2547
|
+
if (tagIds)
|
|
2548
|
+
for (const id of tagIds)
|
|
2549
|
+
if (!/^[0-9a-f-]{36}$/i.test(id))
|
|
2550
|
+
throw new Error(`--tags: "${id}" is not a tag UUID (see: conduyt tags list)`);
|
|
2551
|
+
const minScore = boundedIntFlag(opts.minScore, "--min-score", 0, 1000);
|
|
2552
|
+
const maxScore = boundedIntFlag(opts.maxScore, "--max-score", 0, 1000);
|
|
2553
|
+
const createdWithinDays = boundedIntFlag(opts.addedWithinDays, "--added-within-days", 1, 365);
|
|
2554
|
+
const claimLimit = boundedIntFlag(opts.claimLimit, "--claim-limit", 0, 200);
|
|
2555
|
+
if (claimLimit === null)
|
|
2556
|
+
throw new Error("--claim-limit takes 0-200 (0 = no cap), not none");
|
|
2557
|
+
const next = {
|
|
2558
|
+
enabled: opts.enabled !== undefined ? onOffArg(opts.enabled, "--enabled") : stored.enabled,
|
|
2559
|
+
tagIds: tagIds ?? stored.tagIds,
|
|
2560
|
+
sources: listFlag(opts.sources) ?? stored.sources,
|
|
2561
|
+
minScore: minScore === undefined ? stored.minScore : minScore,
|
|
2562
|
+
maxScore: maxScore === undefined ? stored.maxScore : maxScore,
|
|
2563
|
+
createdWithinDays: createdWithinDays === undefined ? stored.createdWithinDays : createdWithinDays,
|
|
2564
|
+
};
|
|
2565
|
+
if (next.minScore !== null && next.maxScore !== null && next.maxScore < next.minScore)
|
|
2566
|
+
throw new Error(`--max-score (${next.maxScore}) must be at least --min-score (${next.minScore})`);
|
|
2567
|
+
const hasRule = next.tagIds.length > 0 || next.sources.length > 0 || next.minScore !== null || next.maxScore !== null || next.createdWithinDays !== null;
|
|
2568
|
+
if (next.enabled && !hasRule)
|
|
2569
|
+
throw new Error("enabled with no rule would read as disabled — set at least one of --tags, --sources, --min-score, --max-score, --added-within-days, or --enabled off");
|
|
2570
|
+
if (opts.enabled === undefined && tagIds === undefined && opts.sources === undefined && minScore === undefined && maxScore === undefined && createdWithinDays === undefined && claimLimit === undefined) {
|
|
2571
|
+
throw new Error("nothing to change — pass at least one flag");
|
|
2572
|
+
}
|
|
2573
|
+
const body = { poolFilter: next };
|
|
2574
|
+
if (claimLimit !== undefined)
|
|
2575
|
+
body.poolClaimDailyLimit = claimLimit;
|
|
2576
|
+
return patchGeneralSettings(client, body);
|
|
2577
|
+
}));
|
|
2578
|
+
leadPool
|
|
2579
|
+
.command("up-for-grabs")
|
|
2580
|
+
.description("The Up for Grabs queue as the rep page shows it (GET /api/v1/up-for-grabs, up-for-grabs scope): open claim offers plus the unassigned leads the curated pool admits (highest score first, up to 200) with a teaser each, the active poolFilter (tag names resolved) and the criteria line. Claim one with POST /api/v1/up-for-grabs/{contactId}/claim.")
|
|
2581
|
+
.action(run(async (client) => {
|
|
2582
|
+
const result = (await client.get("/api/v1/up-for-grabs"));
|
|
2583
|
+
const data = result?.data ?? {};
|
|
2584
|
+
const pf = data.poolFilter && typeof data.poolFilter === "object" ? data.poolFilter : null;
|
|
2585
|
+
const filter = pf
|
|
2586
|
+
? { enabled: pf.enabled === true, tagIds: (pf.tags ?? []).map((t) => t.id), sources: pf.sources ?? [], minScore: pf.minScore ?? null, maxScore: pf.maxScore ?? null, createdWithinDays: pf.createdWithinDays ?? null }
|
|
2587
|
+
: { enabled: false, tagIds: [], sources: [], minScore: null, maxScore: null, createdWithinDays: null };
|
|
2588
|
+
const offers = Array.isArray(data.offers) ? data.offers : [];
|
|
2589
|
+
return { data: { offers, count: offers.length, poolFilter: pf, criteria: poolCriteriaPhrases(filter, pf?.tags ?? [], pf?.tagLookupFailed === true) } };
|
|
2590
|
+
}));
|
|
2443
2591
|
const lifecycle = program
|
|
2444
2592
|
.command("lifecycle")
|
|
2445
2593
|
.description("Lifecycle settings: lead master statuses, intake-deal creation, how the tenant works leads, and lost propagation");
|
package/package.json
CHANGED