node-autotask 0.69.0 → 0.69.1
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/CHANGELOG.md +14 -0
- package/MCP_TOOL_CATALOG.json +1 -1
- package/capabilities.json +4 -4
- package/dist/capabilities-data.js +3 -3
- package/dist/{chunk-2BB7OASJ.js → chunk-64BMSXWT.js} +2 -2
- package/dist/{chunk-JLBSUZ5B.cjs → chunk-CLHDTYWO.cjs} +600 -258
- package/dist/{chunk-24GRFW55.cjs → chunk-EWXRFHPP.cjs} +175 -175
- package/dist/{chunk-QDBJCGQD.js → chunk-FK37JXSJ.js} +600 -258
- package/dist/{chunk-AH6WAGPS.js → chunk-MMGO3SFL.js} +1 -1
- package/dist/{chunk-DPRY3CUJ.cjs → chunk-WFVLF7EW.cjs} +30 -30
- package/dist/{index-WZ3A8nG6.d.cts → index-BT_0tTPS.d.cts} +3 -3
- package/dist/{index-CxBU31jT.d.ts → index-Coe7LFLY.d.ts} +3 -3
- package/dist/index.cjs +83 -83
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +4 -4
- package/dist/operations/index.cjs +49 -49
- package/dist/operations/index.d.cts +2 -2
- package/dist/operations/index.d.ts +2 -2
- package/dist/operations/index.js +1 -1
- package/dist/pool.cjs +11 -11
- package/dist/pool.js +3 -3
- package/dist/resources/index.cjs +26 -26
- package/dist/resources/index.d.cts +1 -1
- package/dist/resources/index.d.ts +1 -1
- package/dist/resources/index.js +2 -2
- package/docs/API.md +8 -0
- package/docs/performance-reads.md +63 -0
- package/package.json +1 -1
|
@@ -666,6 +666,7 @@ var TtlCache = class {
|
|
|
666
666
|
* its last subscriber leaves. A fresh load starts a new flight and prevents
|
|
667
667
|
* an older flight from replacing its result; invalidation detaches flights
|
|
668
668
|
* without changing the answer owed to their existing subscribers.
|
|
669
|
+
* `shouldStore` controls retention, never the result returned to subscribers.
|
|
669
670
|
* @internal
|
|
670
671
|
*/
|
|
671
672
|
async load(key, loader, opts) {
|
|
@@ -691,7 +692,7 @@ var TtlCache = class {
|
|
|
691
692
|
}
|
|
692
693
|
};
|
|
693
694
|
}).then((value) => {
|
|
694
|
-
if (this.loads.get(key) === created && !controller.signal.aborted) this.set(key, value, epoch);
|
|
695
|
+
if (this.loads.get(key) === created && !controller.signal.aborted && (opts.shouldStore?.(value) ?? true)) this.set(key, value, epoch);
|
|
695
696
|
return value;
|
|
696
697
|
});
|
|
697
698
|
const settled = () => {
|
|
@@ -1531,8 +1532,8 @@ function buildFilter(conditions) {
|
|
|
1531
1532
|
if (list.length === 0) {
|
|
1532
1533
|
throw new AutotaskConfigError("buildFilter requires at least one condition");
|
|
1533
1534
|
}
|
|
1534
|
-
const
|
|
1535
|
-
const filter = { filter: [
|
|
1535
|
+
const root3 = list.length === 1 ? list[0] : { op: "and", items: list };
|
|
1536
|
+
const filter = { filter: [root3] };
|
|
1536
1537
|
validateFilter(filter);
|
|
1537
1538
|
return filter;
|
|
1538
1539
|
}
|
|
@@ -1852,6 +1853,10 @@ var Semaphore = class {
|
|
|
1852
1853
|
maxConcurrent;
|
|
1853
1854
|
inFlight = 0;
|
|
1854
1855
|
waitQueue = /* @__PURE__ */ new Set();
|
|
1856
|
+
/** Synchronous eligibility check; acquisition must follow without an await. @internal */
|
|
1857
|
+
canAcquire() {
|
|
1858
|
+
return this.inFlight < this.maxConcurrent && this.waitQueue.size === 0;
|
|
1859
|
+
}
|
|
1855
1860
|
acquire(signal) {
|
|
1856
1861
|
if (signal?.aborted) return Promise.reject(signal.reason);
|
|
1857
1862
|
if (this.inFlight < this.maxConcurrent) {
|
|
@@ -14271,13 +14276,43 @@ function canonicalObjectKey(url) {
|
|
|
14271
14276
|
|
|
14272
14277
|
// src/http/object-threads.ts
|
|
14273
14278
|
var REGISTRY2 = /* @__PURE__ */ Symbol.for("node-autotask.object-thread-gates.v1");
|
|
14279
|
+
var NOTIFY = /* @__PURE__ */ Symbol.for("node-autotask.object-thread-notify.v1");
|
|
14274
14280
|
var OBJECT_THREAD_LIMIT = 3;
|
|
14275
14281
|
var state = globalThis;
|
|
14276
|
-
|
|
14277
|
-
|
|
14282
|
+
function unsupported() {
|
|
14283
|
+
return new AutotaskConfigError("Unsupported shared object-thread semaphore; refusing admission");
|
|
14284
|
+
}
|
|
14285
|
+
function available(semaphore) {
|
|
14286
|
+
const legacy = semaphore;
|
|
14287
|
+
if (!Number.isInteger(legacy.inFlight) || legacy.inFlight < 0 || legacy.inFlight > OBJECT_THREAD_LIMIT || legacy.maxConcurrent !== OBJECT_THREAD_LIMIT || !(legacy.waitQueue instanceof Set)) {
|
|
14288
|
+
throw unsupported();
|
|
14289
|
+
}
|
|
14290
|
+
return legacy.inFlight < OBJECT_THREAD_LIMIT && legacy.waitQueue.size === 0 && (typeof semaphore.canAcquire !== "function" || semaphore.canAcquire());
|
|
14291
|
+
}
|
|
14292
|
+
function observe(semaphore, notify) {
|
|
14293
|
+
let notifications = semaphore[NOTIFY];
|
|
14294
|
+
if (notifications === void 0) {
|
|
14295
|
+
notifications = { listeners: /* @__PURE__ */ new Map() };
|
|
14296
|
+
semaphore[NOTIFY] = notifications;
|
|
14297
|
+
const original = semaphore.release;
|
|
14298
|
+
const shared = notifications;
|
|
14299
|
+
semaphore.release = function() {
|
|
14300
|
+
original.call(this);
|
|
14301
|
+
for (const listener of shared.listeners.keys()) listener();
|
|
14302
|
+
};
|
|
14303
|
+
}
|
|
14304
|
+
const listeners = notifications.listeners;
|
|
14305
|
+
listeners.set(notify, (listeners.get(notify) ?? 0) + 1);
|
|
14306
|
+
return () => {
|
|
14307
|
+
const count = listeners.get(notify) ?? 0;
|
|
14308
|
+
if (count <= 1) listeners.delete(notify);
|
|
14309
|
+
else listeners.set(notify, count - 1);
|
|
14310
|
+
};
|
|
14311
|
+
}
|
|
14312
|
+
function retainObjectThread(url, trackingIdentifier) {
|
|
14278
14313
|
const target = new URL(url);
|
|
14279
14314
|
const object = canonicalObjectKey(target.pathname);
|
|
14280
|
-
if (object === void 0) return
|
|
14315
|
+
if (object === void 0) return void 0;
|
|
14281
14316
|
const key = crypto.createHash("sha256").update(JSON.stringify([target.origin, trackingIdentifier.trim().toLowerCase(), object])).digest("hex");
|
|
14282
14317
|
const registry2 = state[REGISTRY2] ??= /* @__PURE__ */ new Map();
|
|
14283
14318
|
let entry = registry2.get(key);
|
|
@@ -14286,24 +14321,260 @@ async function acquireObjectThread(url, trackingIdentifier, signal) {
|
|
|
14286
14321
|
registry2.set(key, entry);
|
|
14287
14322
|
}
|
|
14288
14323
|
const active = entry;
|
|
14324
|
+
if (!Number.isInteger(active.users) || active.users < 0 || typeof active.semaphore?.acquire !== "function" || typeof active.semaphore.release !== "function") {
|
|
14325
|
+
throw unsupported();
|
|
14326
|
+
}
|
|
14327
|
+
available(active.semaphore);
|
|
14289
14328
|
active.users += 1;
|
|
14290
|
-
|
|
14291
|
-
|
|
14292
|
-
|
|
14329
|
+
let left = false;
|
|
14330
|
+
return {
|
|
14331
|
+
identity: active,
|
|
14332
|
+
listen: (notify) => observe(active.semaphore, notify),
|
|
14333
|
+
available: () => available(active.semaphore),
|
|
14334
|
+
acquire: (signal) => active.semaphore.acquire(signal),
|
|
14335
|
+
release: () => active.semaphore.release(),
|
|
14336
|
+
leave: () => {
|
|
14337
|
+
if (left) return;
|
|
14338
|
+
left = true;
|
|
14339
|
+
active.users -= 1;
|
|
14340
|
+
if (active.users === 0 && registry2.get(key) === active) registry2.delete(key);
|
|
14341
|
+
}
|
|
14293
14342
|
};
|
|
14294
|
-
|
|
14295
|
-
|
|
14296
|
-
|
|
14297
|
-
|
|
14298
|
-
|
|
14343
|
+
}
|
|
14344
|
+
|
|
14345
|
+
// src/http/transport-admission.ts
|
|
14346
|
+
var KEY = /* @__PURE__ */ Symbol.for("node-autotask.transport-admission.v2");
|
|
14347
|
+
var root2 = globalThis;
|
|
14348
|
+
var coordinator = root2[KEY] ??= { ready: { rows: [], available: () => true }, dirty: /* @__PURE__ */ new Set(), objects: /* @__PURE__ */ new Map(), signals: /* @__PURE__ */ new WeakMap(), sequence: 0, draining: false, batching: 0 };
|
|
14349
|
+
function subscribe(signal, aborted) {
|
|
14350
|
+
let queue = coordinator.signals.get(signal);
|
|
14351
|
+
if (queue === void 0) {
|
|
14352
|
+
const callbacks = /* @__PURE__ */ new Set();
|
|
14353
|
+
queue = { callbacks, listener: () => {
|
|
14354
|
+
coordinator.signals.delete(signal);
|
|
14355
|
+
coordinator.batching += 1;
|
|
14356
|
+
try {
|
|
14357
|
+
for (const callback of callbacks) callback();
|
|
14358
|
+
} finally {
|
|
14359
|
+
coordinator.batching -= 1;
|
|
14360
|
+
drain();
|
|
14361
|
+
}
|
|
14362
|
+
} };
|
|
14363
|
+
coordinator.signals.set(signal, queue);
|
|
14364
|
+
signal.addEventListener("abort", queue.listener, { once: true });
|
|
14299
14365
|
}
|
|
14300
|
-
|
|
14366
|
+
const shared = queue;
|
|
14367
|
+
shared.callbacks.add(aborted);
|
|
14301
14368
|
return () => {
|
|
14302
|
-
|
|
14303
|
-
|
|
14304
|
-
|
|
14305
|
-
|
|
14369
|
+
shared.callbacks.delete(aborted);
|
|
14370
|
+
if (shared.callbacks.size === 0) {
|
|
14371
|
+
coordinator.signals.delete(signal);
|
|
14372
|
+
signal.removeEventListener("abort", shared.listener);
|
|
14373
|
+
}
|
|
14374
|
+
};
|
|
14375
|
+
}
|
|
14376
|
+
function earlier(a, b) {
|
|
14377
|
+
return a.head.sequence < b.head.sequence;
|
|
14378
|
+
}
|
|
14379
|
+
function swap(heap, a, b) {
|
|
14380
|
+
const rows = heap.rows;
|
|
14381
|
+
[rows[a], rows[b]] = [rows[b], rows[a]];
|
|
14382
|
+
rows[a].index = a;
|
|
14383
|
+
rows[b].index = b;
|
|
14384
|
+
}
|
|
14385
|
+
function remove(pair) {
|
|
14386
|
+
const heap = pair.heap;
|
|
14387
|
+
if (heap === void 0) return;
|
|
14388
|
+
const index = pair.index;
|
|
14389
|
+
const last = heap.rows.pop();
|
|
14390
|
+
pair.heap = void 0;
|
|
14391
|
+
if (last === pair) return;
|
|
14392
|
+
heap.rows[index] = last;
|
|
14393
|
+
last.index = index;
|
|
14394
|
+
let current = index;
|
|
14395
|
+
while (current > 0) {
|
|
14396
|
+
const parent = Math.floor((current - 1) / 2);
|
|
14397
|
+
if (!earlier(heap.rows[current], heap.rows[parent])) break;
|
|
14398
|
+
swap(heap, current, parent);
|
|
14399
|
+
current = parent;
|
|
14400
|
+
}
|
|
14401
|
+
if (current !== index) return;
|
|
14402
|
+
for (; ; ) {
|
|
14403
|
+
const left = current * 2 + 1;
|
|
14404
|
+
const right = left + 1;
|
|
14405
|
+
if (left >= heap.rows.length) break;
|
|
14406
|
+
const child = right < heap.rows.length && earlier(heap.rows[right], heap.rows[left]) ? right : left;
|
|
14407
|
+
if (!earlier(heap.rows[child], heap.rows[current])) break;
|
|
14408
|
+
swap(heap, current, child);
|
|
14409
|
+
current = child;
|
|
14410
|
+
}
|
|
14411
|
+
}
|
|
14412
|
+
function insert(heap, pair) {
|
|
14413
|
+
pair.heap = heap;
|
|
14414
|
+
pair.index = heap.rows.length;
|
|
14415
|
+
heap.rows.push(pair);
|
|
14416
|
+
let current = pair.index;
|
|
14417
|
+
while (current > 0) {
|
|
14418
|
+
const parent = Math.floor((current - 1) / 2);
|
|
14419
|
+
if (!earlier(heap.rows[current], heap.rows[parent])) break;
|
|
14420
|
+
swap(heap, current, parent);
|
|
14421
|
+
current = parent;
|
|
14422
|
+
}
|
|
14423
|
+
}
|
|
14424
|
+
function reconsider(pair) {
|
|
14425
|
+
const origin = pair.origin;
|
|
14426
|
+
pair.origin = void 0;
|
|
14427
|
+
remove(pair);
|
|
14428
|
+
if (origin !== void 0) coordinator.dirty.add(origin);
|
|
14429
|
+
if (pair.head === void 0) return false;
|
|
14430
|
+
if (pair.client.active >= pair.client.maxConcurrent) insert(pair.client.waiting, pair);
|
|
14431
|
+
else if (pair.object !== void 0 && !pair.object.gate.available()) insert(pair.object.waiting, pair);
|
|
14432
|
+
else {
|
|
14433
|
+
insert(coordinator.ready, pair);
|
|
14434
|
+
return true;
|
|
14435
|
+
}
|
|
14436
|
+
return false;
|
|
14437
|
+
}
|
|
14438
|
+
function unlink(ticket) {
|
|
14439
|
+
const pair = ticket.pair;
|
|
14440
|
+
if (ticket.previous !== void 0) ticket.previous.next = ticket.next;
|
|
14441
|
+
else pair.head = ticket.next;
|
|
14442
|
+
if (ticket.next !== void 0) ticket.next.previous = ticket.previous;
|
|
14443
|
+
else pair.tail = ticket.previous;
|
|
14444
|
+
ticket.previous = void 0;
|
|
14445
|
+
ticket.next = void 0;
|
|
14446
|
+
if (pair.head === void 0) pair.client.pairs.delete(pair.object?.gate.identity);
|
|
14447
|
+
}
|
|
14448
|
+
function drain() {
|
|
14449
|
+
if (coordinator.draining || coordinator.batching > 0) return;
|
|
14450
|
+
coordinator.draining = true;
|
|
14451
|
+
try {
|
|
14452
|
+
for (; ; ) {
|
|
14453
|
+
for (const heap of coordinator.dirty) {
|
|
14454
|
+
coordinator.dirty.delete(heap);
|
|
14455
|
+
while (heap.rows.length > 0 && heap.available()) {
|
|
14456
|
+
const pair2 = heap.rows[0];
|
|
14457
|
+
if (reconsider(pair2)) {
|
|
14458
|
+
pair2.origin = heap;
|
|
14459
|
+
break;
|
|
14460
|
+
}
|
|
14461
|
+
}
|
|
14462
|
+
}
|
|
14463
|
+
const pair = coordinator.ready.rows[0];
|
|
14464
|
+
if (pair === void 0) break;
|
|
14465
|
+
remove(pair);
|
|
14466
|
+
if (pair.client.active >= pair.client.maxConcurrent || pair.object !== void 0 && !pair.object.gate.available()) {
|
|
14467
|
+
reconsider(pair);
|
|
14468
|
+
continue;
|
|
14469
|
+
}
|
|
14470
|
+
const origin = pair.origin;
|
|
14471
|
+
pair.origin = void 0;
|
|
14472
|
+
if (origin !== void 0) coordinator.dirty.add(origin);
|
|
14473
|
+
const ticket = pair.head;
|
|
14474
|
+
unlink(ticket);
|
|
14475
|
+
ticket.grant();
|
|
14476
|
+
if (pair.head !== void 0) reconsider(pair);
|
|
14477
|
+
}
|
|
14478
|
+
} finally {
|
|
14479
|
+
coordinator.draining = false;
|
|
14480
|
+
}
|
|
14481
|
+
}
|
|
14482
|
+
function wake(heap) {
|
|
14483
|
+
coordinator.dirty.add(heap);
|
|
14484
|
+
drain();
|
|
14485
|
+
}
|
|
14486
|
+
function admissionClient(maxConcurrent) {
|
|
14487
|
+
const client = { maxConcurrent, active: 0, pairs: /* @__PURE__ */ new Map(), waiting: { rows: [], available: () => client.active < client.maxConcurrent } };
|
|
14488
|
+
return client;
|
|
14489
|
+
}
|
|
14490
|
+
async function acquireTransport(client, url, trackingIdentifier, signal) {
|
|
14491
|
+
if (signal.aborted) throw signal.reason;
|
|
14492
|
+
const retained = retainObjectThread(url, trackingIdentifier);
|
|
14493
|
+
let object = retained === void 0 ? void 0 : coordinator.objects.get(retained.identity);
|
|
14494
|
+
if (retained !== void 0 && object === void 0) {
|
|
14495
|
+
object = { gate: retained, references: 0, stop: () => void 0, waiting: { rows: [], available: () => retained.available() } };
|
|
14496
|
+
const shared = object;
|
|
14497
|
+
shared.stop = retained.listen(() => wake(shared.waiting));
|
|
14498
|
+
coordinator.objects.set(retained.identity, shared);
|
|
14499
|
+
}
|
|
14500
|
+
if (object !== void 0) object.references += 1;
|
|
14501
|
+
const drop = () => {
|
|
14502
|
+
retained?.leave();
|
|
14503
|
+
if (object !== void 0 && --object.references === 0) {
|
|
14504
|
+
object.stop();
|
|
14505
|
+
coordinator.objects.delete(object.gate.identity);
|
|
14506
|
+
}
|
|
14306
14507
|
};
|
|
14508
|
+
let pair = client.pairs.get(retained?.identity);
|
|
14509
|
+
if (pair === void 0) {
|
|
14510
|
+
pair = { client, object, index: -1 };
|
|
14511
|
+
client.pairs.set(retained?.identity, pair);
|
|
14512
|
+
}
|
|
14513
|
+
const queue = pair;
|
|
14514
|
+
return new Promise((resolve, reject) => {
|
|
14515
|
+
let released = false;
|
|
14516
|
+
let unsubscribe = () => void 0;
|
|
14517
|
+
const leave = () => {
|
|
14518
|
+
if (released) return;
|
|
14519
|
+
released = true;
|
|
14520
|
+
coordinator.batching += 1;
|
|
14521
|
+
client.active -= 1;
|
|
14522
|
+
coordinator.dirty.add(client.waiting);
|
|
14523
|
+
try {
|
|
14524
|
+
retained?.release();
|
|
14525
|
+
} finally {
|
|
14526
|
+
drop();
|
|
14527
|
+
coordinator.batching -= 1;
|
|
14528
|
+
drain();
|
|
14529
|
+
}
|
|
14530
|
+
};
|
|
14531
|
+
const aborted = () => {
|
|
14532
|
+
const front = queue.head === ticket;
|
|
14533
|
+
if (front) remove(queue);
|
|
14534
|
+
unlink(ticket);
|
|
14535
|
+
unsubscribe();
|
|
14536
|
+
drop();
|
|
14537
|
+
reject(signal.reason);
|
|
14538
|
+
if (front) reconsider(queue);
|
|
14539
|
+
drain();
|
|
14540
|
+
};
|
|
14541
|
+
const ticket = {
|
|
14542
|
+
sequence: coordinator.sequence++,
|
|
14543
|
+
pair: queue,
|
|
14544
|
+
grant: () => {
|
|
14545
|
+
unsubscribe();
|
|
14546
|
+
client.active += 1;
|
|
14547
|
+
let acquired;
|
|
14548
|
+
try {
|
|
14549
|
+
acquired = retained?.acquire(signal) ?? Promise.resolve();
|
|
14550
|
+
} catch (error) {
|
|
14551
|
+
client.active -= 1;
|
|
14552
|
+
drop();
|
|
14553
|
+
reject(error);
|
|
14554
|
+
wake(client.waiting);
|
|
14555
|
+
return;
|
|
14556
|
+
}
|
|
14557
|
+
void acquired.then(() => {
|
|
14558
|
+
if (signal.aborted) {
|
|
14559
|
+
leave();
|
|
14560
|
+
reject(signal.reason);
|
|
14561
|
+
} else resolve(leave);
|
|
14562
|
+
}, (error) => {
|
|
14563
|
+
client.active -= 1;
|
|
14564
|
+
drop();
|
|
14565
|
+
reject(error);
|
|
14566
|
+
wake(client.waiting);
|
|
14567
|
+
});
|
|
14568
|
+
}
|
|
14569
|
+
};
|
|
14570
|
+
ticket.previous = queue.tail;
|
|
14571
|
+
if (queue.tail !== void 0) queue.tail.next = ticket;
|
|
14572
|
+
else queue.head = ticket;
|
|
14573
|
+
queue.tail = ticket;
|
|
14574
|
+
unsubscribe = subscribe(signal, aborted);
|
|
14575
|
+
if (queue.head === ticket) reconsider(queue);
|
|
14576
|
+
drain();
|
|
14577
|
+
});
|
|
14307
14578
|
}
|
|
14308
14579
|
|
|
14309
14580
|
// src/http/credentials.ts
|
|
@@ -14559,8 +14830,8 @@ var HttpClient = class {
|
|
|
14559
14830
|
maxResponseBytes;
|
|
14560
14831
|
/** Local hourly budget (undefined when `rateLimit.perHour` is off). */
|
|
14561
14832
|
hourly;
|
|
14562
|
-
/**
|
|
14563
|
-
|
|
14833
|
+
/** Client identity for atomic local/object capacity admission. */
|
|
14834
|
+
admission;
|
|
14564
14835
|
/** Tenant 429 cooldown gate (issue #6; ON by default). */
|
|
14565
14836
|
cooldownEnabled;
|
|
14566
14837
|
cooldownMaxMs;
|
|
@@ -14623,7 +14894,7 @@ var HttpClient = class {
|
|
|
14623
14894
|
this.cooldownMaxMs = config.cooldown.maxMs;
|
|
14624
14895
|
this.cooldownDefaultMs = config.cooldown.defaultMs;
|
|
14625
14896
|
this.maxConcurrent = config.maxConcurrent;
|
|
14626
|
-
this.
|
|
14897
|
+
this.admission = admissionClient(config.maxConcurrent);
|
|
14627
14898
|
this.timeoutMs = config.timeoutMs;
|
|
14628
14899
|
this.logger = config.logger;
|
|
14629
14900
|
this.redactPersonalData = config.redactPersonalData;
|
|
@@ -14830,7 +15101,7 @@ var HttpClient = class {
|
|
|
14830
15101
|
}
|
|
14831
15102
|
// ---- the attempt --------------------------------------------------------
|
|
14832
15103
|
/**
|
|
14833
|
-
*
|
|
15104
|
+
* Acquire client/object capacity together, charge the attempt, fetch and read the body.
|
|
14834
15105
|
* `retry` when a network error is retriable (already waited); throws the
|
|
14835
15106
|
* typed error otherwise. The permit is released on every path.
|
|
14836
15107
|
*/
|
|
@@ -14838,24 +15109,22 @@ var HttpClient = class {
|
|
|
14838
15109
|
const { method, opts, ctx } = s;
|
|
14839
15110
|
let release;
|
|
14840
15111
|
for (; ; ) {
|
|
15112
|
+
let releaseThreads;
|
|
14841
15113
|
try {
|
|
14842
|
-
await this.
|
|
15114
|
+
releaseThreads = await acquireTransport(this.admission, s.url, this.auth.apiIntegrationCode, s.signal);
|
|
14843
15115
|
} catch (err) {
|
|
14844
15116
|
if (s.signal.aborted) throw this.interrupted(s);
|
|
14845
15117
|
throw err;
|
|
14846
15118
|
}
|
|
14847
|
-
let releaseObject = () => void 0;
|
|
14848
15119
|
let finishHourly = () => void 0;
|
|
14849
15120
|
let released = false;
|
|
14850
15121
|
const releaseCurrent = () => {
|
|
14851
15122
|
if (released) return;
|
|
14852
15123
|
released = true;
|
|
14853
15124
|
finishHourly();
|
|
14854
|
-
|
|
14855
|
-
this.semaphore.release();
|
|
15125
|
+
releaseThreads();
|
|
14856
15126
|
};
|
|
14857
15127
|
try {
|
|
14858
|
-
releaseObject = await acquireObjectThread(s.url, this.auth.apiIntegrationCode, s.signal);
|
|
14859
15128
|
if (s.signal.aborted || Date.now() >= s.deadlineAt) throw this.interrupted(s);
|
|
14860
15129
|
this.gate(s, false);
|
|
14861
15130
|
if (s.signal.aborted || Date.now() >= s.deadlineAt) throw this.interrupted(s);
|
|
@@ -15575,6 +15844,56 @@ var WORKFLOW_RESOURCES = [
|
|
|
15575
15844
|
"projects"
|
|
15576
15845
|
];
|
|
15577
15846
|
|
|
15847
|
+
// src/utils/bounded.ts
|
|
15848
|
+
async function runBounded(fn, items, opts) {
|
|
15849
|
+
const { concurrency, signal, settle } = opts;
|
|
15850
|
+
if (!Number.isInteger(concurrency) || concurrency <= 0) {
|
|
15851
|
+
throw new AutotaskConfigError("batch concurrency must be a positive integer");
|
|
15852
|
+
}
|
|
15853
|
+
const results = new Array(items.length);
|
|
15854
|
+
let next = 0;
|
|
15855
|
+
let failure;
|
|
15856
|
+
const fail = (error, index) => {
|
|
15857
|
+
if (failure === void 0 || opts.orderedErrors === true && index < failure.index) failure = { error, index };
|
|
15858
|
+
};
|
|
15859
|
+
const worker = async () => {
|
|
15860
|
+
while (failure === void 0 && next < items.length) {
|
|
15861
|
+
if (signal?.aborted) {
|
|
15862
|
+
fail(signal.reason, -1);
|
|
15863
|
+
return;
|
|
15864
|
+
}
|
|
15865
|
+
const i = next++;
|
|
15866
|
+
try {
|
|
15867
|
+
const item = items[i];
|
|
15868
|
+
const value = await (signal === void 0 ? fn(item) : runWithSignal(signal, () => fn(item)));
|
|
15869
|
+
results[i] = settle ? { status: "fulfilled", value } : value;
|
|
15870
|
+
} catch (error) {
|
|
15871
|
+
if (settle) results[i] = { status: "rejected", reason: error };
|
|
15872
|
+
else fail(error, i);
|
|
15873
|
+
}
|
|
15874
|
+
}
|
|
15875
|
+
};
|
|
15876
|
+
await Promise.all(Array.from({ length: Math.min(concurrency, items.length) }, worker));
|
|
15877
|
+
if (failure !== void 0) throw failure.error;
|
|
15878
|
+
return results;
|
|
15879
|
+
}
|
|
15880
|
+
async function mapReadTasks(http, items, fn) {
|
|
15881
|
+
const signal = ambientCallerSignal();
|
|
15882
|
+
const abort = () => new AutotaskAbortError("Read fan-out aborted by the caller");
|
|
15883
|
+
if (signal?.aborted) throw abort();
|
|
15884
|
+
try {
|
|
15885
|
+
const results = await runBounded(fn, items, { concurrency: http === void 0 ? DEFAULT_MAX_CONCURRENT : http.maxConcurrent, orderedErrors: true, ...signal === void 0 ? {} : { signal } });
|
|
15886
|
+
if (signal?.aborted) throw abort();
|
|
15887
|
+
return results;
|
|
15888
|
+
} catch (error) {
|
|
15889
|
+
if (signal?.aborted && !(error instanceof AutotaskAbortError)) throw abort();
|
|
15890
|
+
throw error;
|
|
15891
|
+
}
|
|
15892
|
+
}
|
|
15893
|
+
function readTasks(http, tasks) {
|
|
15894
|
+
return mapReadTasks(http, tasks, (task) => task());
|
|
15895
|
+
}
|
|
15896
|
+
|
|
15578
15897
|
// src/operations/fieldCatalog.ts
|
|
15579
15898
|
var MAX_FIELD_CATALOG_WIRE = 60;
|
|
15580
15899
|
var FIELD_CATALOG_HONESTY_NOTE = "Live field metadata reports the SHAPE of a field (existence, requiredness, type, maxLength, read-only, queryable, picklist-ness) as FLAGS and NAMES: picklist-ness as a flag (isPickList) and picklist field names (picklistFields). With the opt-in `labels: true`, picklist rows carry the vendor's exposed picklist VALUES (labels next to each value); without it the op serves no VALUES. It cannot resolve a picklist VALUE the vendor does not expose to this API user (a vendor-withheld picklist value): retrying the catalog will not surface a withheld value; that gap is vendor-side, not a client defect.";
|
|
@@ -15847,13 +16166,25 @@ function kindFetches(holder, resource) {
|
|
|
15847
16166
|
udf: () => holder?.getUdfInfo?.() ?? Promise.reject(new AutotaskError(`fieldCatalog: the client exposes no getUdfInfo read for "${resource}"`, { code: "INVALID_RESPONSE", category: "server" }))
|
|
15848
16167
|
};
|
|
15849
16168
|
}
|
|
15850
|
-
async function
|
|
15851
|
-
const
|
|
15852
|
-
const
|
|
16169
|
+
async function readKind(ctx, resource, kind, fetch2) {
|
|
16170
|
+
const cache = ctx.client.http.fieldCache;
|
|
16171
|
+
const peek = cache !== void 0 && !ctx.fresh ? cache.peek(fieldKey(resource, kind)) : { hit: false, age: null };
|
|
16172
|
+
if (peek.hit && cache !== void 0) {
|
|
16173
|
+
return { kind, peek, outcome: { status: "fulfilled", value: cache.get(fieldKey(resource, kind)) } };
|
|
16174
|
+
}
|
|
16175
|
+
try {
|
|
16176
|
+
const value = await fetch2();
|
|
16177
|
+
return { kind, peek, outcome: { status: "fulfilled", value } };
|
|
16178
|
+
} catch (error) {
|
|
16179
|
+
if (!isAutotaskError(error) || error.code === "ABORTED") throw error;
|
|
16180
|
+
return { kind, peek, outcome: { status: "rejected", reason: error } };
|
|
16181
|
+
}
|
|
16182
|
+
}
|
|
16183
|
+
async function sweepResource(ctx, resource, tally, reads) {
|
|
16184
|
+
const { fieldsFilter, labels } = ctx;
|
|
15853
16185
|
const fieldOp = ctx.fieldOps.get(resource);
|
|
15854
16186
|
if (fieldOp === void 0) return void 0;
|
|
15855
16187
|
const apiEntity = apiEntityFor(fieldOp);
|
|
15856
|
-
const holder = client[camelKey(resource)];
|
|
15857
16188
|
const row = {
|
|
15858
16189
|
resource,
|
|
15859
16190
|
apiEntity,
|
|
@@ -15869,8 +16200,6 @@ async function sweepResource(ctx, resource, tally) {
|
|
|
15869
16200
|
wire: 0,
|
|
15870
16201
|
error: null
|
|
15871
16202
|
};
|
|
15872
|
-
const fetches = kindFetches(holder, resource);
|
|
15873
|
-
if (fresh) cache?.invalidate(`${resource}:`);
|
|
15874
16203
|
const projectList = (kind, list) => {
|
|
15875
16204
|
const projected = list.map((f) => projectFieldRow(f, labels, kind === "udf"));
|
|
15876
16205
|
if (kind === "fields") applyFieldsFilter(projected, fieldsFilter, row);
|
|
@@ -15879,28 +16208,18 @@ async function sweepResource(ctx, resource, tally) {
|
|
|
15879
16208
|
};
|
|
15880
16209
|
let allCached = true;
|
|
15881
16210
|
const ages = [];
|
|
15882
|
-
for (const kind of
|
|
15883
|
-
|
|
15884
|
-
|
|
15885
|
-
if (peek.hit === true && cache !== void 0) {
|
|
15886
|
-
const value2 = cache.get(fieldKey(resource, kind));
|
|
15887
|
-
if (kind === "info") row.info = value2 ?? null;
|
|
15888
|
-
else projectList(kind, Array.isArray(value2) ? value2 : []);
|
|
15889
|
-
if (peek.age !== null) ages.push(peek.age);
|
|
15890
|
-
continue;
|
|
15891
|
-
}
|
|
15892
|
-
let value;
|
|
15893
|
-
try {
|
|
15894
|
-
value = await fetches[kind]();
|
|
15895
|
-
} catch (err) {
|
|
15896
|
-
if (!isAutotaskError(err) || err.code === "ABORTED") throw err;
|
|
16211
|
+
for (const { kind, peek, outcome } of reads) {
|
|
16212
|
+
if (!peek.hit) {
|
|
16213
|
+
allCached = false;
|
|
15897
16214
|
tally.wireUsed += 1;
|
|
15898
16215
|
row.wire += 1;
|
|
15899
|
-
|
|
16216
|
+
} else if (peek.age !== null) ages.push(peek.age);
|
|
16217
|
+
if (outcome.status === "rejected") {
|
|
16218
|
+
const error = outcome.reason;
|
|
16219
|
+
if (row.error === null) row.error = { code: error.code, message: error.message };
|
|
15900
16220
|
continue;
|
|
15901
16221
|
}
|
|
15902
|
-
|
|
15903
|
-
row.wire += 1;
|
|
16222
|
+
const value = outcome.value;
|
|
15904
16223
|
if (kind === "info") {
|
|
15905
16224
|
row.info = value ?? null;
|
|
15906
16225
|
} else {
|
|
@@ -15945,9 +16264,20 @@ async function fieldCatalog(client, opts) {
|
|
|
15945
16264
|
const zone = client.config.zone ?? "unknown";
|
|
15946
16265
|
const rows = [];
|
|
15947
16266
|
const tally = { wireUsed: 0, anyPicklistValues: false };
|
|
15948
|
-
const ctx = { client,
|
|
16267
|
+
const ctx = { client, fieldsFilter, labels, compact, fresh: opts?.fresh === true, fieldOps, udfCapable };
|
|
15949
16268
|
for (const resource of targets) {
|
|
15950
|
-
|
|
16269
|
+
apiEntityFor(fieldOps.get(resource));
|
|
16270
|
+
if (ctx.fresh) cache?.invalidate(`${resource}:`);
|
|
16271
|
+
}
|
|
16272
|
+
const tasks = targets.flatMap((resource) => {
|
|
16273
|
+
const holder = client[camelKey(resource)];
|
|
16274
|
+
const fetches = kindFetches(holder, resource);
|
|
16275
|
+
return include.map((kind) => ({ resource, kind, fetch: fetches[kind] }));
|
|
16276
|
+
});
|
|
16277
|
+
const reads = await mapReadTasks(client.http, tasks, ({ resource, kind, fetch: fetch2 }) => readKind(ctx, resource, kind, fetch2));
|
|
16278
|
+
for (let index = 0; index < targets.length; index += 1) {
|
|
16279
|
+
const start = index * include.length;
|
|
16280
|
+
const row = await sweepResource(ctx, targets[index], tally, reads.slice(start, start + include.length));
|
|
15951
16281
|
if (row !== void 0) rows.push(row);
|
|
15952
16282
|
}
|
|
15953
16283
|
const result = {
|
|
@@ -16130,56 +16460,6 @@ function entityNameFromPath(resourcePath) {
|
|
|
16130
16460
|
return snake;
|
|
16131
16461
|
}
|
|
16132
16462
|
|
|
16133
|
-
// src/utils/bounded.ts
|
|
16134
|
-
async function runBounded(fn, items, opts) {
|
|
16135
|
-
const { concurrency, signal, settle } = opts;
|
|
16136
|
-
if (!Number.isInteger(concurrency) || concurrency <= 0) {
|
|
16137
|
-
throw new AutotaskConfigError("batch concurrency must be a positive integer");
|
|
16138
|
-
}
|
|
16139
|
-
const results = new Array(items.length);
|
|
16140
|
-
let next = 0;
|
|
16141
|
-
let failure;
|
|
16142
|
-
const fail = (error, index) => {
|
|
16143
|
-
if (failure === void 0 || opts.orderedErrors === true && index < failure.index) failure = { error, index };
|
|
16144
|
-
};
|
|
16145
|
-
const worker = async () => {
|
|
16146
|
-
while (failure === void 0 && next < items.length) {
|
|
16147
|
-
if (signal?.aborted) {
|
|
16148
|
-
fail(signal.reason, -1);
|
|
16149
|
-
return;
|
|
16150
|
-
}
|
|
16151
|
-
const i = next++;
|
|
16152
|
-
try {
|
|
16153
|
-
const item = items[i];
|
|
16154
|
-
const value = await (signal === void 0 ? fn(item) : runWithSignal(signal, () => fn(item)));
|
|
16155
|
-
results[i] = settle ? { status: "fulfilled", value } : value;
|
|
16156
|
-
} catch (error) {
|
|
16157
|
-
if (settle) results[i] = { status: "rejected", reason: error };
|
|
16158
|
-
else fail(error, i);
|
|
16159
|
-
}
|
|
16160
|
-
}
|
|
16161
|
-
};
|
|
16162
|
-
await Promise.all(Array.from({ length: Math.min(concurrency, items.length) }, worker));
|
|
16163
|
-
if (failure !== void 0) throw failure.error;
|
|
16164
|
-
return results;
|
|
16165
|
-
}
|
|
16166
|
-
async function mapReadTasks(http, items, fn) {
|
|
16167
|
-
const signal = ambientCallerSignal();
|
|
16168
|
-
const abort = () => new AutotaskAbortError("Read fan-out aborted by the caller");
|
|
16169
|
-
if (signal?.aborted) throw abort();
|
|
16170
|
-
try {
|
|
16171
|
-
const results = await runBounded(fn, items, { concurrency: http.maxConcurrent, orderedErrors: true, ...signal === void 0 ? {} : { signal } });
|
|
16172
|
-
if (signal?.aborted) throw abort();
|
|
16173
|
-
return results;
|
|
16174
|
-
} catch (error) {
|
|
16175
|
-
if (signal?.aborted && !(error instanceof AutotaskAbortError)) throw abort();
|
|
16176
|
-
throw error;
|
|
16177
|
-
}
|
|
16178
|
-
}
|
|
16179
|
-
function readTasks(http, tasks) {
|
|
16180
|
-
return mapReadTasks(http, tasks, (task) => task());
|
|
16181
|
-
}
|
|
16182
|
-
|
|
16183
16463
|
// src/operations/nameSnapshot.ts
|
|
16184
16464
|
function nameRecordSnapshot(cache, path, id, operation) {
|
|
16185
16465
|
const body = cache?.get(path);
|
|
@@ -16716,27 +16996,27 @@ function subscriberError(error, operation) {
|
|
|
16716
16996
|
};
|
|
16717
16997
|
return copyValue(error);
|
|
16718
16998
|
}
|
|
16719
|
-
function
|
|
16720
|
-
|
|
16721
|
-
if (cache === void 0) return http.request({ method: "GET", path, operation });
|
|
16999
|
+
function cachedRead(http, cache, key, path, operation, request, fresh, shouldStore) {
|
|
17000
|
+
if (cache === void 0) return request();
|
|
16722
17001
|
let ownsLoader = false;
|
|
16723
17002
|
const loader = (signal) => {
|
|
16724
17003
|
ownsLoader = true;
|
|
16725
|
-
return
|
|
17004
|
+
return request(signal);
|
|
16726
17005
|
};
|
|
16727
17006
|
const options = {
|
|
16728
17007
|
signal: ambientCallerSignal(),
|
|
16729
17008
|
fresh,
|
|
17009
|
+
shouldStore,
|
|
16730
17010
|
abortError: () => new AutotaskAbortError(`Request aborted: GET ${path}`, {
|
|
16731
17011
|
operation,
|
|
16732
17012
|
suggestedAction: "The caller aborted; re-issue the call if still needed."
|
|
16733
17013
|
})
|
|
16734
17014
|
};
|
|
16735
|
-
return cache.load(
|
|
17015
|
+
return cache.load(key, loader, options).catch((error) => {
|
|
16736
17016
|
if (ownsLoader || !(error instanceof AutotaskError) || error.details?.budgetScope !== "client" || error.notSent !== true) throw error;
|
|
16737
17017
|
if (options.signal?.aborted) throw options.abortError();
|
|
16738
|
-
const warm = cache.get(
|
|
16739
|
-
return warm !== void 0 ? warm : cache.load(
|
|
17018
|
+
const warm = cache.get(key);
|
|
17019
|
+
return warm !== void 0 ? warm : cache.load(key, loader, { ...options, fresh: true });
|
|
16740
17020
|
}).catch((error) => {
|
|
16741
17021
|
if (!(error instanceof AutotaskError)) throw error;
|
|
16742
17022
|
const failure = subscriberError(error, operation);
|
|
@@ -16744,6 +17024,33 @@ function cachedRecordGet(http, path, operation, fresh = false) {
|
|
|
16744
17024
|
throw failure;
|
|
16745
17025
|
});
|
|
16746
17026
|
}
|
|
17027
|
+
function cachedRecordGet(http, path, operation, fresh = false) {
|
|
17028
|
+
return cachedRead(
|
|
17029
|
+
http,
|
|
17030
|
+
http.readCache,
|
|
17031
|
+
path,
|
|
17032
|
+
path,
|
|
17033
|
+
operation,
|
|
17034
|
+
(signal) => http.request({ method: "GET", path, operation, signal }),
|
|
17035
|
+
fresh
|
|
17036
|
+
);
|
|
17037
|
+
}
|
|
17038
|
+
function cachedMetadataGet(http, resource, kind, path, operation, unwrap, fresh = false, maxRetries) {
|
|
17039
|
+
const cache = http.fieldCache;
|
|
17040
|
+
const request = (signal) => {
|
|
17041
|
+
return http.request({ method: "GET", path, operation, signal, maxRetries }).then(unwrap).catch((error) => {
|
|
17042
|
+
if (error instanceof AutotaskError && (error.code === "INVALID_RESPONSE" || error.details?.deterministic === true)) {
|
|
17043
|
+
cache?.invalidate(`${resource}:`);
|
|
17044
|
+
}
|
|
17045
|
+
throw error;
|
|
17046
|
+
});
|
|
17047
|
+
};
|
|
17048
|
+
return cachedRead(http, cache, fieldKey(resource, kind), path, operation, request, fresh, (value) => {
|
|
17049
|
+
if (value === null || value === void 0) return false;
|
|
17050
|
+
if (Array.isArray(value)) return value.length > 0;
|
|
17051
|
+
return typeof value !== "object" || Object.keys(value).length > 0;
|
|
17052
|
+
});
|
|
17053
|
+
}
|
|
16747
17054
|
|
|
16748
17055
|
// src/field-sets.ts
|
|
16749
17056
|
var MODEL_FIELD_SETS = {
|
|
@@ -16956,6 +17263,19 @@ async function boundedPart(http, path, conditions, limit, operation, includeFiel
|
|
|
16956
17263
|
return { items, capped, hasMore: capped && pageDetails.nextPageUrl != null };
|
|
16957
17264
|
}
|
|
16958
17265
|
|
|
17266
|
+
// src/utils/model-fields.ts
|
|
17267
|
+
var lookups = /* @__PURE__ */ new Map();
|
|
17268
|
+
function modelFieldLookup(resourceKey) {
|
|
17269
|
+
if (!Object.hasOwn(MODEL_FIELD_SETS, resourceKey)) return void 0;
|
|
17270
|
+
let lookup = lookups.get(resourceKey);
|
|
17271
|
+
if (lookup === void 0) {
|
|
17272
|
+
const names = new Set(MODEL_FIELD_SETS[resourceKey]);
|
|
17273
|
+
lookup = (field) => names.has(field);
|
|
17274
|
+
lookups.set(resourceKey, lookup);
|
|
17275
|
+
}
|
|
17276
|
+
return lookup;
|
|
17277
|
+
}
|
|
17278
|
+
|
|
16959
17279
|
// src/resources/special/_shared/relation-filters.ts
|
|
16960
17280
|
var JOIN_SET_CAP = 300;
|
|
16961
17281
|
function capJoinSet(ids2, cap = JOIN_SET_CAP) {
|
|
@@ -16969,8 +17289,8 @@ var RELATION_TARGETS = {
|
|
|
16969
17289
|
project: { resource: "projects", path: "/V1.0/Projects/query" }
|
|
16970
17290
|
};
|
|
16971
17291
|
function relationsFor(resourceKey) {
|
|
16972
|
-
const
|
|
16973
|
-
return Object.keys(RELATION_TARGETS).filter((rel) =>
|
|
17292
|
+
const hasField = modelFieldLookup(resourceKey);
|
|
17293
|
+
return Object.keys(RELATION_TARGETS).filter((rel) => hasField?.(`${rel}ID`) === true);
|
|
16974
17294
|
}
|
|
16975
17295
|
function selfPrefixes(resourceKey) {
|
|
16976
17296
|
const rels = Object.keys(RELATION_TARGETS).filter((rel) => RELATION_TARGETS[rel].resource === resourceKey);
|
|
@@ -17015,7 +17335,7 @@ function validateRelationLeaves(resourceKey, conditions, op) {
|
|
|
17015
17335
|
if (rest.length > 0 || !sub) fail("is not <relation>.<field> (multi-hop relations are not supported)");
|
|
17016
17336
|
if (!valid.includes(rel)) fail(`names an unknown relation for ${resourceKey} (valid: ${valid.join(", ") || "none"})`);
|
|
17017
17337
|
const parentFields = MODEL_FIELD_SETS[RELATION_TARGETS[rel].resource];
|
|
17018
|
-
if (parentFields !== void 0 &&
|
|
17338
|
+
if (parentFields !== void 0 && modelFieldLookup(RELATION_TARGETS[rel].resource)?.(sub) !== true) {
|
|
17019
17339
|
fail(`names a field unknown on ${RELATION_TARGETS[rel].resource}`);
|
|
17020
17340
|
}
|
|
17021
17341
|
}
|
|
@@ -17026,36 +17346,52 @@ async function rewriteRelationFilters(http, resourceKey, conditions, op) {
|
|
|
17026
17346
|
if (!hasRelationConditions(conditions)) return void 0;
|
|
17027
17347
|
const conds = conditions;
|
|
17028
17348
|
validateRelationLeaves(resourceKey, conds, op);
|
|
17349
|
+
const parentReads = /* @__PURE__ */ new Map();
|
|
17029
17350
|
const parentIds = async (rel, leaves) => {
|
|
17030
17351
|
const target = RELATION_TARGETS[rel];
|
|
17031
17352
|
const parentConds = buildFilter(leaves.map((l) => ({ ...l, field: l.field.slice(rel.length + 1) }))).filter;
|
|
17032
|
-
const
|
|
17033
|
-
|
|
17034
|
-
|
|
17035
|
-
|
|
17036
|
-
|
|
17037
|
-
|
|
17353
|
+
const key = JSON.stringify([target.path, parentConds], (_key, value) => isRecord2(value) ? Object.fromEntries(Object.keys(value).sort().map((name) => [name, value[name]])) : value);
|
|
17354
|
+
let pending = parentReads.get(key);
|
|
17355
|
+
if (pending === void 0) {
|
|
17356
|
+
pending = (async () => {
|
|
17357
|
+
const res = await boundedPart(http, target.path, parentConds, JOIN_SET_CAP, op, ["id"]);
|
|
17358
|
+
if (res.hasMore) {
|
|
17359
|
+
throw new AutotaskConfigError(
|
|
17360
|
+
`${op}: the ${rel}.* conditions match more than ${JOIN_SET_CAP} ${target.resource} \u2014 the ${resourceKey} query was not issued (a partial ${rel} set would give partial results)`,
|
|
17361
|
+
{ operation: op, suggestedAction: `Narrow the ${rel}.* conditions (e.g. add a ${rel} date or status condition) or filter ${resourceKey} by ${rel}ID directly.` }
|
|
17362
|
+
);
|
|
17363
|
+
}
|
|
17364
|
+
return capJoinSet(res.items.map((r) => Number(r.id)).filter((n) => Number.isFinite(n) && n > 0)).ids;
|
|
17365
|
+
})();
|
|
17366
|
+
parentReads.set(key, pending);
|
|
17038
17367
|
}
|
|
17039
|
-
return
|
|
17368
|
+
return [...await pending];
|
|
17040
17369
|
};
|
|
17041
17370
|
const NEVER = null;
|
|
17371
|
+
const rewriteLeaf = async (c) => {
|
|
17372
|
+
const [rel, field] = c.field.split(".");
|
|
17373
|
+
if (selfPrefixes(resourceKey).includes(rel)) return { ...c, field };
|
|
17374
|
+
const ids2 = await parentIds(rel, [c]);
|
|
17375
|
+
return ids2.length === 0 ? void 0 : { field: `${rel}ID`, op: "in", value: ids2 };
|
|
17376
|
+
};
|
|
17042
17377
|
const rewrite = async (list, mode) => {
|
|
17378
|
+
if (mode === "or" && !list.some((c) => Array.isArray(c.items) && hasRelationConditions(c.items))) {
|
|
17379
|
+
const parts = await mapReadTasks(http, list, (c) => isRelationLeaf(c) ? rewriteLeaf(c) : Promise.resolve(c));
|
|
17380
|
+
const out2 = parts.filter((c) => c !== void 0);
|
|
17381
|
+
return out2.length === 0 ? NEVER : out2;
|
|
17382
|
+
}
|
|
17043
17383
|
const out = [];
|
|
17044
17384
|
const byRel = /* @__PURE__ */ new Map();
|
|
17045
17385
|
for (const c of list) {
|
|
17046
17386
|
if (isRelationLeaf(c)) {
|
|
17047
17387
|
const parts = c.field.split(".");
|
|
17048
|
-
if (parts.length === 2 && selfPrefixes(resourceKey).includes(parts[0])) {
|
|
17049
|
-
|
|
17388
|
+
if (mode === "or" || parts.length === 2 && selfPrefixes(resourceKey).includes(parts[0])) {
|
|
17389
|
+
const leaf = await rewriteLeaf(c);
|
|
17390
|
+
if (leaf !== void 0) out.push(leaf);
|
|
17050
17391
|
continue;
|
|
17051
17392
|
}
|
|
17052
17393
|
const rel = parts[0];
|
|
17053
|
-
|
|
17054
|
-
byRel.set(rel, [...byRel.get(rel) ?? [], c]);
|
|
17055
|
-
continue;
|
|
17056
|
-
}
|
|
17057
|
-
const ids2 = await parentIds(rel, [c]);
|
|
17058
|
-
if (ids2.length > 0) out.push({ field: `${rel}ID`, op: "in", value: ids2 });
|
|
17394
|
+
byRel.set(rel, [...byRel.get(rel) ?? [], c]);
|
|
17059
17395
|
continue;
|
|
17060
17396
|
}
|
|
17061
17397
|
if (isRecord2(c) && (c.op === "and" || c.op === "or") && Array.isArray(c.items) && hasRelationConditions(c.items)) {
|
|
@@ -17092,6 +17428,17 @@ var ROW_FK_TABLES = {
|
|
|
17092
17428
|
billingCodeID: "billingCode"
|
|
17093
17429
|
};
|
|
17094
17430
|
var isResourceFkField = (field) => field === "resourceID" || field.endsWith("ResourceID");
|
|
17431
|
+
function rowNamePlan(rows, resourceKey, picklistFields = []) {
|
|
17432
|
+
const builder = createNamePlan(picklistFields, resourceKey);
|
|
17433
|
+
for (const row of rows) {
|
|
17434
|
+
for (const [field, value] of Object.entries(row)) {
|
|
17435
|
+
const table = ROW_FK_TABLES[field];
|
|
17436
|
+
if (table !== void 0) builder.addFk(table, value);
|
|
17437
|
+
else if (isResourceFkField(field)) builder.addResource(value);
|
|
17438
|
+
}
|
|
17439
|
+
}
|
|
17440
|
+
return builder.plan();
|
|
17441
|
+
}
|
|
17095
17442
|
var LABEL_NAME_MAX_CHARS = 200;
|
|
17096
17443
|
function untrustedName(name) {
|
|
17097
17444
|
if (name === null) return null;
|
|
@@ -17110,8 +17457,8 @@ async function labelRows(client, resourceKey, rows) {
|
|
|
17110
17457
|
for (const row of rows) for (const k of Object.keys(row)) keys.add(k);
|
|
17111
17458
|
if (keys.size === 0) return { rows: [...rows] };
|
|
17112
17459
|
let picklistFields = [];
|
|
17113
|
-
const
|
|
17114
|
-
const candidates = [...keys].filter((f) => f !== "id" &&
|
|
17460
|
+
const modelHas = modelFieldLookup(resourceKey);
|
|
17461
|
+
const candidates = [...keys].filter((f) => f !== "id" && modelHas?.(f) === true && ROW_FK_TABLES[f] === void 0 && !isResourceFkField(f));
|
|
17115
17462
|
if (candidates.length > 0) {
|
|
17116
17463
|
try {
|
|
17117
17464
|
const catalog = await fieldCatalog(client, { resources: [resourceKey], labels: true });
|
|
@@ -17125,16 +17472,7 @@ async function labelRows(client, resourceKey, rows) {
|
|
|
17125
17472
|
}
|
|
17126
17473
|
const labelled = (field) => picklistFields.includes(field) || ROW_FK_TABLES[field] !== void 0 || isResourceFkField(field);
|
|
17127
17474
|
if (![...keys].some(labelled)) return { rows: [...rows] };
|
|
17128
|
-
const
|
|
17129
|
-
for (const row of rows) {
|
|
17130
|
-
for (const [field, value] of Object.entries(row)) {
|
|
17131
|
-
const table = ROW_FK_TABLES[field];
|
|
17132
|
-
if ((value === 0 || value === "0") && table !== "company") continue;
|
|
17133
|
-
if (table !== void 0) builder.addFk(table, value);
|
|
17134
|
-
else if (isResourceFkField(field)) builder.addResource(value);
|
|
17135
|
-
}
|
|
17136
|
-
}
|
|
17137
|
-
const plan = builder.plan();
|
|
17475
|
+
const plan = rowNamePlan(rows, resourceKey, picklistFields);
|
|
17138
17476
|
const names = plan.resourceIds.length === 0 && plan.recordFks.length === 0 && picklistFields.length === 0 ? void 0 : await resolveCompositeNames(client.http, plan);
|
|
17139
17477
|
const out = rows.map((row) => {
|
|
17140
17478
|
const r = { ...row };
|
|
@@ -17162,16 +17500,34 @@ async function labelFetchResults(client, result) {
|
|
|
17162
17500
|
if (r.found && r.value !== null) byResource2.set(r.resource, [...byResource2.get(r.resource) ?? [], i]);
|
|
17163
17501
|
});
|
|
17164
17502
|
const results = [...result.results];
|
|
17503
|
+
const groups = [...byResource2].map(([resource, indices]) => ({ resource, indices, rows: indices.map((i) => results[i].value) }));
|
|
17504
|
+
const seen = /* @__PURE__ */ new Set();
|
|
17505
|
+
let dependent = false;
|
|
17506
|
+
for (const group of groups) {
|
|
17507
|
+
const plan = rowNamePlan(group.rows, group.resource);
|
|
17508
|
+
const targets = [...plan.resourceIds.map((id) => `resource:${String(id)}`), ...plan.recordFks.map((fk2) => `${fk2.table}:${String(fk2.id)}`)];
|
|
17509
|
+
for (const target of targets) {
|
|
17510
|
+
if (seen.has(target)) dependent = true;
|
|
17511
|
+
seen.add(target);
|
|
17512
|
+
}
|
|
17513
|
+
}
|
|
17514
|
+
const labelledGroups = /* @__PURE__ */ new Map();
|
|
17515
|
+
const labelled = await mapReadTasks(
|
|
17516
|
+
dependent ? { maxConcurrent: 1 } : client.http,
|
|
17517
|
+
groups,
|
|
17518
|
+
async (group) => ({ resource: group.resource, result: await labelRows(client, group.resource, group.rows) })
|
|
17519
|
+
);
|
|
17520
|
+
for (const group of labelled) labelledGroups.set(group.resource, group.result);
|
|
17165
17521
|
const notes = [];
|
|
17166
17522
|
const reasons = {};
|
|
17167
17523
|
for (const [resource, indices] of byResource2) {
|
|
17168
|
-
const
|
|
17524
|
+
const labelled2 = labelledGroups.get(resource);
|
|
17169
17525
|
indices.forEach((idx, j) => {
|
|
17170
|
-
results[idx] = { ...results[idx], value:
|
|
17526
|
+
results[idx] = { ...results[idx], value: labelled2.rows[j] };
|
|
17171
17527
|
});
|
|
17172
|
-
if (
|
|
17173
|
-
notes.push(
|
|
17174
|
-
for (const [field, why] of Object.entries(
|
|
17528
|
+
if (labelled2.names !== void 0) {
|
|
17529
|
+
notes.push(labelled2.names.note);
|
|
17530
|
+
for (const [field, why] of Object.entries(labelled2.names.reasons ?? {})) reasons[field] = why;
|
|
17175
17531
|
}
|
|
17176
17532
|
}
|
|
17177
17533
|
if (notes.length === 0) return { ...result, results };
|
|
@@ -17761,8 +18117,8 @@ var MetaBase = class extends QueryBase {
|
|
|
17761
18117
|
return cachedRecordGet(this.http, path, operation, fresh);
|
|
17762
18118
|
}
|
|
17763
18119
|
/**
|
|
17764
|
-
* Entity-metadata read through the
|
|
17765
|
-
*
|
|
18120
|
+
* Entity-metadata read through the default-on field cache (issue #31;
|
|
18121
|
+
* with no fieldCache this is exactly one `http.request` — the
|
|
17766
18122
|
* bit-for-bit uncached trio path). One private helper beside `cachedGet`,
|
|
17767
18123
|
* for the same three reasons the read cache exists: a vendor drift
|
|
17768
18124
|
* (deterministic 500, INVALID_RESPONSE) must not be served stale, repeat
|
|
@@ -17770,7 +18126,9 @@ var MetaBase = class extends QueryBase {
|
|
|
17770
18126
|
* duplicate requests. The UNWRAPPED value is stored (never the raw
|
|
17771
18127
|
* envelope); an EMPTY or FAILED result is never cached (a failure
|
|
17772
18128
|
* rejects before any `set`; an empty is refused by the cache itself);
|
|
17773
|
-
* concurrent callers share
|
|
18129
|
+
* concurrent callers share one wire with independent cancellation and cloned
|
|
18130
|
+
* values; invalidation detaches older reads before they can repopulate
|
|
18131
|
+
* the cache. The drift signal
|
|
17774
18132
|
* (the INVALID_RESPONSE shape drift, the deterministic validation 500)
|
|
17775
18133
|
* invalidates THIS entity's entries so the next call refetches
|
|
17776
18134
|
* (transport-level signals are also invalidated in the transport's own
|
|
@@ -17779,29 +18137,7 @@ var MetaBase = class extends QueryBase {
|
|
|
17779
18137
|
* @internal
|
|
17780
18138
|
*/
|
|
17781
18139
|
async cachedMeta(kind, path, operation, unwrap, fresh = false) {
|
|
17782
|
-
|
|
17783
|
-
if (cache === void 0) {
|
|
17784
|
-
const res = await this.http.request({ method: "GET", path, operation });
|
|
17785
|
-
return unwrap(res);
|
|
17786
|
-
}
|
|
17787
|
-
const key = fieldKey(this.config.key, kind);
|
|
17788
|
-
if (!fresh) {
|
|
17789
|
-
const shared = cache.inflight(key);
|
|
17790
|
-
if (shared !== void 0) return shared;
|
|
17791
|
-
const hit = cache.get(key);
|
|
17792
|
-
if (hit !== void 0) return hit;
|
|
17793
|
-
}
|
|
17794
|
-
const work = this.http.request({ method: "GET", path, operation }).then((body) => {
|
|
17795
|
-
const value = unwrap(body);
|
|
17796
|
-
if (!isEmpty(value)) cache.set(key, value);
|
|
17797
|
-
return value;
|
|
17798
|
-
});
|
|
17799
|
-
work.catch((err) => {
|
|
17800
|
-
if (err instanceof AutotaskError && (err.code === "INVALID_RESPONSE" || err.details?.deterministic === true)) {
|
|
17801
|
-
cache.invalidate(`${this.config.key}:`);
|
|
17802
|
-
}
|
|
17803
|
-
});
|
|
17804
|
-
return cache.track(key, work);
|
|
18140
|
+
return cachedMetadataGet(this.http, this.config.key, kind, path, operation, unwrap, fresh);
|
|
17805
18141
|
}
|
|
17806
18142
|
/** `GET /V1.0/<E>/{id}` → `{ item }` unwrapped (`item: null` → NotFoundError). */
|
|
17807
18143
|
async getGlobal(id, fresh = false) {
|
|
@@ -18107,8 +18443,8 @@ var MetaBase = class extends QueryBase {
|
|
|
18107
18443
|
);
|
|
18108
18444
|
}
|
|
18109
18445
|
const leaf = fields.map((field) => ({ field, op: "eq", value }));
|
|
18110
|
-
const
|
|
18111
|
-
const items = await this.queryPage1([
|
|
18446
|
+
const root3 = leaf.length === 1 ? leaf[0] : { op: "or", items: leaf };
|
|
18447
|
+
const items = await this.queryPage1([root3], 2);
|
|
18112
18448
|
if (items.length === 1) {
|
|
18113
18449
|
return { value: items[0], resolutionCost: "server-filter", scanned: 0, scanTruncated: false };
|
|
18114
18450
|
}
|
|
@@ -18275,7 +18611,7 @@ var MetaBase = class extends QueryBase {
|
|
|
18275
18611
|
}
|
|
18276
18612
|
const limit = opts.limit === void 0 ? 25 : clampPageSize(opts.limit);
|
|
18277
18613
|
const leaf = fields.map((field) => ({ field, op: "contains", value: text }));
|
|
18278
|
-
const
|
|
18614
|
+
const root3 = leaf.length === 1 ? leaf[0] : { op: "or", items: leaf };
|
|
18279
18615
|
for (const key of Object.keys(opts)) {
|
|
18280
18616
|
if (key !== "limit" && key !== "companyID" && key !== "includeFields") {
|
|
18281
18617
|
throw new AutotaskConfigError(`search: unknown opts key "${key}" \u2014 the bag is closed: limit, companyID, includeFields`);
|
|
@@ -18289,7 +18625,7 @@ var MetaBase = class extends QueryBase {
|
|
|
18289
18625
|
}
|
|
18290
18626
|
const companyID = opts.companyID === void 0 ? void 0 : Number(opts.companyID);
|
|
18291
18627
|
const includeFields = opts.includeFields === void 0 ? void 0 : opts.includeFields.includes("id") ? opts.includeFields : ["id", ...opts.includeFields];
|
|
18292
|
-
const conditions = companyID === void 0 ? [
|
|
18628
|
+
const conditions = companyID === void 0 ? [root3] : [{ field: "companyID", op: "eq", value: companyID }, root3];
|
|
18293
18629
|
const rows = await this.queryEntity(`${this.resourcePath}/query`, conditions, {
|
|
18294
18630
|
maxRecords: limit,
|
|
18295
18631
|
...includeFields !== void 0 ? { includeFields } : {}
|
|
@@ -18320,11 +18656,6 @@ var MetaBase = class extends QueryBase {
|
|
|
18320
18656
|
return this.searchBase(value, { limit });
|
|
18321
18657
|
}
|
|
18322
18658
|
};
|
|
18323
|
-
function isEmpty(value) {
|
|
18324
|
-
if (value === null || value === void 0) return true;
|
|
18325
|
-
if (Array.isArray(value)) return value.length === 0;
|
|
18326
|
-
return typeof value === "object" && Object.keys(value).length === 0;
|
|
18327
|
-
}
|
|
18328
18659
|
|
|
18329
18660
|
// src/resources/base/mutations.ts
|
|
18330
18661
|
var MutationBase = class extends MetaBase {
|
|
@@ -20562,20 +20893,20 @@ var GenericResource = class extends BaseResource {
|
|
|
20562
20893
|
this.requireHelper("getContext");
|
|
20563
20894
|
const cfg = this.config;
|
|
20564
20895
|
const rootField = cfg.contextRootField ?? this.config.key;
|
|
20565
|
-
const
|
|
20566
|
-
const result = { [rootField]:
|
|
20896
|
+
const root3 = await this.fetchRecordRaw(this.config.resourcePath, id, cfg.contextRootFresh === true);
|
|
20897
|
+
const result = { [rootField]: root3 };
|
|
20567
20898
|
const parts = cfg.contextParts ?? [];
|
|
20568
|
-
const values = await mapReadTasks(this.http, parts, ([, idField, targetPath]) => this.contextFetch(targetPath,
|
|
20899
|
+
const values = await mapReadTasks(this.http, parts, ([, idField, targetPath]) => this.contextFetch(targetPath, root3[idField]));
|
|
20569
20900
|
for (const [i, [name]] of parts.entries()) result[name] = values[i];
|
|
20570
20901
|
if (opts.names === true) {
|
|
20571
20902
|
const builder = createNamePlan();
|
|
20572
20903
|
for (const sib of cfg.nameSiblings ?? []) {
|
|
20573
|
-
const fk2 =
|
|
20904
|
+
const fk2 = root3[sib.field];
|
|
20574
20905
|
if (sib.kind === "resource") builder.addResource(fk2);
|
|
20575
20906
|
else builder.addFk(sib.kind, fk2);
|
|
20576
20907
|
}
|
|
20577
20908
|
const names = await resolveCompositeNames(this.http, builder.plan(), { maxNameReads: opts.maxNameReads });
|
|
20578
|
-
const row = { ...
|
|
20909
|
+
const row = { ...root3 };
|
|
20579
20910
|
for (const sib of cfg.nameSiblings ?? []) {
|
|
20580
20911
|
addNameSibling(row, sib.field, (v) => sib.kind === "resource" ? names.resourceName(v) : names.recordName(sib.kind, v));
|
|
20581
20912
|
}
|
|
@@ -20855,12 +21186,14 @@ function readIncludeNames(record, includeFields) {
|
|
|
20855
21186
|
return names;
|
|
20856
21187
|
}
|
|
20857
21188
|
function resolveAuthority(record, live) {
|
|
20858
|
-
if (live !== null) return { known: live, authority: "the tenant's live entity field metadata" };
|
|
21189
|
+
if (live !== null) return { known: live, authority: "the tenant's live entity field metadata", hasField: (name) => live.includes(name) };
|
|
20859
21190
|
const vendored = MODEL_FIELD_SETS[record.resource];
|
|
21191
|
+
const modelHas = modelFieldLookup(record.resource);
|
|
20860
21192
|
const liveOnlyExempt = Array.isArray(record.metadata?.liveOnlyFields) ? record.metadata.liveOnlyFields : [];
|
|
20861
|
-
if (vendored === void 0) return void 0;
|
|
21193
|
+
if (vendored === void 0 || modelHas === void 0) return void 0;
|
|
20862
21194
|
return {
|
|
20863
21195
|
known: [...vendored, ...liveOnlyExempt],
|
|
21196
|
+
hasField: (name) => modelHas(name) || liveOnlyExempt.includes(name),
|
|
20864
21197
|
authority: liveOnlyExempt.length > 0 ? "the vendored spec (src/field-sets.ts) + the plan-pinned live-only fields (exempt from the vendored refusal)" : "the vendored spec (src/field-sets.ts)"
|
|
20865
21198
|
};
|
|
20866
21199
|
}
|
|
@@ -20910,8 +21243,8 @@ async function findUnknownFieldNames(record, holder, lists) {
|
|
|
20910
21243
|
const resolved = resolveAuthority(record, await liveFieldNames(holder));
|
|
20911
21244
|
if (resolved === void 0) return void 0;
|
|
20912
21245
|
const unknown = {};
|
|
20913
|
-
for (const [key, names] of Object.entries(lists)) unknown[key] = [...new Set(names.filter((name) => !resolved.
|
|
20914
|
-
return {
|
|
21246
|
+
for (const [key, names] of Object.entries(lists)) unknown[key] = [...new Set(names.filter((name) => !resolved.hasField(name)))];
|
|
21247
|
+
return { known: resolved.known, authority: resolved.authority, unknown };
|
|
20915
21248
|
}
|
|
20916
21249
|
|
|
20917
21250
|
// src/resources/special/_shared/ticketStatus.ts
|
|
@@ -20931,25 +21264,13 @@ function picklistOf(fields) {
|
|
|
20931
21264
|
return out;
|
|
20932
21265
|
}
|
|
20933
21266
|
async function readFields(http, fresh) {
|
|
20934
|
-
|
|
20935
|
-
const key = fieldKey("tickets", "fields");
|
|
20936
|
-
if (!fresh && cache !== void 0) {
|
|
20937
|
-
const shared = cache.inflight(key);
|
|
20938
|
-
if (shared !== void 0) return await shared;
|
|
20939
|
-
const hit = cache.get(key);
|
|
20940
|
-
if (hit !== void 0) return hit;
|
|
20941
|
-
}
|
|
20942
|
-
const epoch = cache?.epoch;
|
|
20943
|
-
const work = (async () => {
|
|
20944
|
-
const res = await http.request({ method: "GET", path: "/V1.0/Tickets/entityInformation/fields", operation: OP, maxRetries: 0 });
|
|
21267
|
+
return cachedMetadataGet(http, "tickets", "fields", "/V1.0/Tickets/entityInformation/fields", OP, (res) => {
|
|
20945
21268
|
const fields = res?.fields;
|
|
20946
21269
|
if (!Array.isArray(fields)) {
|
|
20947
21270
|
throw new AutotaskError("Expected the FieldInformationResultModel envelope { fields: [] }; got a different shape", { code: "INVALID_RESPONSE", category: "server" });
|
|
20948
21271
|
}
|
|
20949
|
-
if (fields.length > 0) cache?.set(key, fields, epoch);
|
|
20950
21272
|
return fields;
|
|
20951
|
-
})
|
|
20952
|
-
return cache !== void 0 && !fresh ? cache.track(key, work) : work;
|
|
21273
|
+
}, fresh, 0);
|
|
20953
21274
|
}
|
|
20954
21275
|
function assumed(allowAssumed, operation) {
|
|
20955
21276
|
if (!allowAssumed) {
|
|
@@ -21039,7 +21360,8 @@ function validateProjection(fields) {
|
|
|
21039
21360
|
const names = [...new Set(list)];
|
|
21040
21361
|
const entity = PART_ENTITY[part];
|
|
21041
21362
|
const known = MODEL_FIELD_SETS[entity] ?? [];
|
|
21042
|
-
const
|
|
21363
|
+
const hasField = modelFieldLookup(entity);
|
|
21364
|
+
const unknown = names.filter((n) => hasField?.(n) !== true);
|
|
21043
21365
|
if (unknown.length > 0) {
|
|
21044
21366
|
throw new AutotaskConfigError(
|
|
21045
21367
|
`fullProfile: fields.${part} has unknown field name(s) ${formatUnknownNameList(unknown)} against the vendored spec for ${entity} (${known.length} fields; operations.fieldCatalog resources: ["${entity}"] lists the live set) \u2014 no request was issued`
|
|
@@ -21310,7 +21632,7 @@ async function prepareCrmWrite(resource, input) {
|
|
|
21310
21632
|
if (input.intent === "create_company" && status !== "matched") {
|
|
21311
21633
|
const eff = effectiveRequiredFields(null, RELATIONSHIP_MAP.companies?.zoneFacts);
|
|
21312
21634
|
const research = (f) => ["companyType", "ownerResourceID", "countryID"].includes(f) ? "lookup" : "web_if_available_else_ask";
|
|
21313
|
-
const
|
|
21635
|
+
const lookups2 = {
|
|
21314
21636
|
companyType: { via: "operations.fieldCatalog", resource: "companies", field: "companyType", labels: true, note: "map the user wording to one returned label; never hardcode ids" },
|
|
21315
21637
|
ownerResourceID: { via: "resources.get / the staff resolver", note: "owners cannot be enumerated on a blind surface: take a known resource id and confirm it with resources.get" },
|
|
21316
21638
|
countryID: { via: "countries.query", note: "resolve the country name to an id; never guess" }
|
|
@@ -21321,7 +21643,7 @@ async function prepareCrmWrite(resource, input) {
|
|
|
21321
21643
|
];
|
|
21322
21644
|
for (const [f, source] of wanted) {
|
|
21323
21645
|
if (has(co[f]) || needsInput.some((n) => n.field === f)) continue;
|
|
21324
|
-
needsInput.push({ field: f, why: source === "policy" ? `CRM policy: a new company needs ${f} (the vendor auto-creates a "Primary Address" location from it)` : `the vendor requires ${f} to create a company`, source, ...
|
|
21646
|
+
needsInput.push({ field: f, why: source === "policy" ? `CRM policy: a new company needs ${f} (the vendor auto-creates a "Primary Address" location from it)` : `the vendor requires ${f} to create a company`, source, ...lookups2[f] ? { lookup: lookups2[f] } : {}, research: research(f) });
|
|
21325
21647
|
}
|
|
21326
21648
|
}
|
|
21327
21649
|
if (input.intent === "add_contact") {
|
|
@@ -21876,10 +22198,10 @@ var CompaniesResource = class extends GenericResource {
|
|
|
21876
22198
|
* fetch; no sub-lists; absent/dangling references come back null). */
|
|
21877
22199
|
async getContext(id) {
|
|
21878
22200
|
const company = await this.fetchRecordRaw("/V1.0/Companies", id);
|
|
21879
|
-
const
|
|
22201
|
+
const root3 = company;
|
|
21880
22202
|
const [ownerResource, parentCompany] = await readTasks(this.http, [
|
|
21881
|
-
() => this.contextFetch("/V1.0/Resources",
|
|
21882
|
-
() => this.contextFetch("/V1.0/Companies",
|
|
22203
|
+
() => this.contextFetch("/V1.0/Resources", root3["ownerResourceID"]),
|
|
22204
|
+
() => this.contextFetch("/V1.0/Companies", root3["parentCompanyID"])
|
|
21883
22205
|
]);
|
|
21884
22206
|
return { company, ownerResource, parentCompany };
|
|
21885
22207
|
}
|
|
@@ -22147,6 +22469,14 @@ var DEFAULT_LIMIT2 = 25;
|
|
|
22147
22469
|
function resourceFor(client, key) {
|
|
22148
22470
|
return client[camelKey(key)];
|
|
22149
22471
|
}
|
|
22472
|
+
function searchable(client, key) {
|
|
22473
|
+
const holder = resourceFor(client, key);
|
|
22474
|
+
return holder !== void 0 && typeof holder.search === "function" && (typeof holder.hasSearch !== "function" || holder.hasSearch()) ? holder : void 0;
|
|
22475
|
+
}
|
|
22476
|
+
async function searchRows(holder, text, limit) {
|
|
22477
|
+
const matches = await holder.search(text, { limit });
|
|
22478
|
+
return Array.isArray(matches) ? matches.filter((m) => typeof m === "object" && m !== null) : [];
|
|
22479
|
+
}
|
|
22150
22480
|
async function searchAcrossResources(client, query, opts = {}) {
|
|
22151
22481
|
const text = query.trim();
|
|
22152
22482
|
if (text === "") {
|
|
@@ -22163,12 +22493,23 @@ async function searchAcrossResources(client, query, opts = {}) {
|
|
|
22163
22493
|
}
|
|
22164
22494
|
const results = [];
|
|
22165
22495
|
const skipped = [];
|
|
22496
|
+
if (totalLimit === void 0) {
|
|
22497
|
+
const completed = await mapReadTasks(client.http, keys, async (key) => {
|
|
22498
|
+
const holder = searchable(client, key);
|
|
22499
|
+
return holder === void 0 ? void 0 : { resource: key, matches: await searchRows(holder, text, limit) };
|
|
22500
|
+
});
|
|
22501
|
+
completed.forEach((row, i) => {
|
|
22502
|
+
if (row === void 0) skipped.push(keys[i]);
|
|
22503
|
+
else results.push(row);
|
|
22504
|
+
});
|
|
22505
|
+
return { query: text, results, skipped };
|
|
22506
|
+
}
|
|
22166
22507
|
const notSearched = [];
|
|
22167
|
-
let remaining = totalLimit
|
|
22508
|
+
let remaining = totalLimit;
|
|
22168
22509
|
let hitQuota = false;
|
|
22169
22510
|
for (const key of keys) {
|
|
22170
|
-
const holder =
|
|
22171
|
-
if (holder === void 0
|
|
22511
|
+
const holder = searchable(client, key);
|
|
22512
|
+
if (holder === void 0) {
|
|
22172
22513
|
skipped.push(key);
|
|
22173
22514
|
continue;
|
|
22174
22515
|
}
|
|
@@ -22177,14 +22518,12 @@ async function searchAcrossResources(client, query, opts = {}) {
|
|
|
22177
22518
|
continue;
|
|
22178
22519
|
}
|
|
22179
22520
|
const ask = Math.min(limit, remaining);
|
|
22180
|
-
const
|
|
22181
|
-
|
|
22182
|
-
if (totalLimit !== void 0) rows.length = Math.min(rows.length, ask);
|
|
22521
|
+
const rows = await searchRows(holder, text, ask);
|
|
22522
|
+
rows.length = Math.min(rows.length, ask);
|
|
22183
22523
|
results.push({ resource: key, matches: rows });
|
|
22184
22524
|
remaining -= rows.length;
|
|
22185
22525
|
if (rows.length === ask) hitQuota = true;
|
|
22186
22526
|
}
|
|
22187
|
-
if (totalLimit === void 0) return { query: text, results, skipped };
|
|
22188
22527
|
return { query: text, results, skipped, notSearched, truncated: notSearched.length > 0 || hitQuota };
|
|
22189
22528
|
}
|
|
22190
22529
|
|
|
@@ -22216,11 +22555,10 @@ async function resolveAny(client, identifier, opts = {}) {
|
|
|
22216
22555
|
}
|
|
22217
22556
|
const configuredCap = Math.min(client.config?.resolution?.maxScanRecords ?? 500, 500);
|
|
22218
22557
|
const limit = Math.min(opts.limit ?? configuredCap, configuredCap);
|
|
22219
|
-
const results =
|
|
22220
|
-
for (const key of keys) {
|
|
22558
|
+
const results = await mapReadTasks(client.http, keys, async (key) => {
|
|
22221
22559
|
const holder = resourceFor2(client, key);
|
|
22222
22560
|
if (holder === void 0 || typeof holder.resolveDetailed !== "function") {
|
|
22223
|
-
|
|
22561
|
+
return {
|
|
22224
22562
|
resource: key,
|
|
22225
22563
|
value: null,
|
|
22226
22564
|
resolutionCost: missCost(identifier),
|
|
@@ -22228,8 +22566,7 @@ async function resolveAny(client, identifier, opts = {}) {
|
|
|
22228
22566
|
scanTruncated: false,
|
|
22229
22567
|
candidates: [],
|
|
22230
22568
|
error: "NO_RESOLVE"
|
|
22231
|
-
}
|
|
22232
|
-
continue;
|
|
22569
|
+
};
|
|
22233
22570
|
}
|
|
22234
22571
|
try {
|
|
22235
22572
|
const r = await holder.resolveDetailed(identifier);
|
|
@@ -22241,7 +22578,7 @@ async function resolveAny(client, identifier, opts = {}) {
|
|
|
22241
22578
|
scanTruncated: r.scanTruncated,
|
|
22242
22579
|
candidates: (r.candidates ?? []).map((c) => c.id)
|
|
22243
22580
|
};
|
|
22244
|
-
|
|
22581
|
+
return outcome;
|
|
22245
22582
|
} catch (err) {
|
|
22246
22583
|
let code;
|
|
22247
22584
|
let candidates = [];
|
|
@@ -22256,7 +22593,7 @@ async function resolveAny(client, identifier, opts = {}) {
|
|
|
22256
22593
|
} else {
|
|
22257
22594
|
throw err;
|
|
22258
22595
|
}
|
|
22259
|
-
|
|
22596
|
+
return {
|
|
22260
22597
|
resource: key,
|
|
22261
22598
|
value: null,
|
|
22262
22599
|
resolutionCost: missCost(identifier),
|
|
@@ -22264,9 +22601,9 @@ async function resolveAny(client, identifier, opts = {}) {
|
|
|
22264
22601
|
scanTruncated: code === "RESOLUTION_TRUNCATED",
|
|
22265
22602
|
candidates,
|
|
22266
22603
|
error: code
|
|
22267
|
-
}
|
|
22604
|
+
};
|
|
22268
22605
|
}
|
|
22269
|
-
}
|
|
22606
|
+
});
|
|
22270
22607
|
const cleanMiss = results.every((r) => r.value === null && r.candidates.length === 0 && !r.scanTruncated && (r.error === void 0 || r.error === "NOT_FOUND"));
|
|
22271
22608
|
if (match === "auto" && typeof identifier === "string" && !/^\d+$/.test(identifier.trim()) && cleanMiss) {
|
|
22272
22609
|
const contains = await searchAcrossResources(client, identifier, { resources: keys, limit });
|
|
@@ -22833,6 +23170,7 @@ var shortName = (operation) => operation.split(".").pop() ?? operation;
|
|
|
22833
23170
|
// src/operations/fetchByIds.ts
|
|
22834
23171
|
var FETCH_BY_IDS_MAX_ITEMS = 500;
|
|
22835
23172
|
var FETCH_BY_IDS_CHUNK_SIZE = 250;
|
|
23173
|
+
var itemKey = (resource, id) => `${resource}:${String(id)}`;
|
|
22836
23174
|
function project2(value, fields) {
|
|
22837
23175
|
const out = {};
|
|
22838
23176
|
for (const f of fields) {
|
|
@@ -22886,7 +23224,8 @@ function validateFetchManyItems(items, cap, opName = "fetchByIds", capRef = `FET
|
|
|
22886
23224
|
}
|
|
22887
23225
|
const resourceKey = item.resource;
|
|
22888
23226
|
const fields = MODEL_FIELD_SETS[resourceKey];
|
|
22889
|
-
|
|
23227
|
+
const hasField = modelFieldLookup(resourceKey);
|
|
23228
|
+
if (fields === void 0 || hasField === void 0) {
|
|
22890
23229
|
problems.push(
|
|
22891
23230
|
`${at}.resource: "${resourceKey}" is not a single-record GETtable resource (${Object.keys(MODEL_FIELD_SETS).length} known) \u2014 see autotask_catalog for the exact plan keys`
|
|
22892
23231
|
);
|
|
@@ -22921,7 +23260,7 @@ function validateFetchManyItems(items, cap, opName = "fetchByIds", capRef = `FET
|
|
|
22921
23260
|
continue;
|
|
22922
23261
|
}
|
|
22923
23262
|
for (const f of item.fields) {
|
|
22924
|
-
if (!
|
|
23263
|
+
if (!hasField(f)) {
|
|
22925
23264
|
problems.push(
|
|
22926
23265
|
`${at}.fields: "${f}" is not a field of ${resourceKey} \u2014 a hallucinated field is a shape error, not a silent projection-miss (exact vendor field names via operations.fieldCatalog)`
|
|
22927
23266
|
);
|
|
@@ -22961,7 +23300,7 @@ async function fetchByIds(client, items, opts = {}) {
|
|
|
22961
23300
|
groups.set(item.resource, g);
|
|
22962
23301
|
}
|
|
22963
23302
|
const byKey2 = /* @__PURE__ */ new Map();
|
|
22964
|
-
|
|
23303
|
+
const plans = [...groups].map(([key, group]) => {
|
|
22965
23304
|
const holder = client[camelKey(key)];
|
|
22966
23305
|
if (holder === void 0) {
|
|
22967
23306
|
throw new AutotaskConfigError(`fetchByIds: the client exposes no accessor for resource "${key}"`, {
|
|
@@ -22979,7 +23318,10 @@ async function fetchByIds(client, items, opts = {}) {
|
|
|
22979
23318
|
}
|
|
22980
23319
|
}
|
|
22981
23320
|
const includeFields = group.anyFields && group.indices.every((i) => items[i].fields !== void 0) ? [...group.fields] : void 0;
|
|
22982
|
-
const kOf = (id) =>
|
|
23321
|
+
const kOf = (id) => itemKey(key, id);
|
|
23322
|
+
return { key, holder, resourcePath, unique, includeFields, kOf };
|
|
23323
|
+
});
|
|
23324
|
+
await mapReadTasks(client.http, plans, async ({ key, resourcePath, unique, includeFields, kOf }) => {
|
|
22983
23325
|
const foundRows = await fetchIdChunks(client.http, resourcePath, unique, includeFields, `${key}.fetchByIds`, {
|
|
22984
23326
|
chunkSize: FETCH_BY_IDS_CHUNK_SIZE,
|
|
22985
23327
|
maxRecords: FETCH_BY_IDS_CHUNK_SIZE,
|
|
@@ -22998,30 +23340,30 @@ async function fetchByIds(client, items, opts = {}) {
|
|
|
22998
23340
|
const q = kOf(k);
|
|
22999
23341
|
if (!byKey2.has(q)) byKey2.set(q, { found: true, value: row });
|
|
23000
23342
|
}
|
|
23001
|
-
|
|
23002
|
-
|
|
23003
|
-
|
|
23004
|
-
|
|
23005
|
-
|
|
23006
|
-
|
|
23007
|
-
|
|
23008
|
-
|
|
23009
|
-
|
|
23010
|
-
|
|
23011
|
-
|
|
23012
|
-
|
|
23013
|
-
|
|
23014
|
-
|
|
23015
|
-
|
|
23016
|
-
|
|
23343
|
+
});
|
|
23344
|
+
const missing = plans.flatMap((plan) => plan.unique.filter((id) => !byKey2.has(plan.kOf(id))).map((id) => ({ plan, id })));
|
|
23345
|
+
await mapReadTasks(client.http, missing, async ({ plan: { holder, kOf }, id }) => {
|
|
23346
|
+
const k = kOf(id);
|
|
23347
|
+
try {
|
|
23348
|
+
const value = await holder.get(id);
|
|
23349
|
+
byKey2.set(k, { found: true, value });
|
|
23350
|
+
} catch (err) {
|
|
23351
|
+
if (err instanceof NotFoundError) {
|
|
23352
|
+
byKey2.set(k, { found: false, value: null, error: { code: "NOT_FOUND", message: err.message } });
|
|
23353
|
+
} else if (isAutotaskError(err) && err.code !== "ABORTED") {
|
|
23354
|
+
const e = { code: err.code, message: err.message };
|
|
23355
|
+
if (err.httpStatus !== void 0) e.httpStatus = err.httpStatus;
|
|
23356
|
+
byKey2.set(k, { found: false, value: null, error: e });
|
|
23357
|
+
} else {
|
|
23358
|
+
throw err;
|
|
23017
23359
|
}
|
|
23018
23360
|
}
|
|
23019
|
-
}
|
|
23361
|
+
});
|
|
23020
23362
|
const results = [];
|
|
23021
23363
|
for (let i = 0; i < items.length; i += 1) {
|
|
23022
23364
|
const item = items[i];
|
|
23023
23365
|
const id = canonical[i];
|
|
23024
|
-
const out = byKey2.get(
|
|
23366
|
+
const out = byKey2.get(itemKey(item.resource, id));
|
|
23025
23367
|
const value = out.found ? item.fields !== void 0 ? project2(out.value, item.fields) : out.value : null;
|
|
23026
23368
|
results.push(
|
|
23027
23369
|
out.found ? { resource: item.resource, id, found: true, value } : { resource: item.resource, id, found: false, value: null, error: out.error }
|
|
@@ -24363,17 +24705,17 @@ async function fetchCharges(ctx) {
|
|
|
24363
24705
|
const raw = await ctx.readPart("/V1.0/ContractCharges/query", chargesCond, ["id", "chargeType", "billableAmount", "extendedCost", "unitCost", "unitPrice", "unitQuantity", "datePurchased", "isBilled", "status", "contractServiceID"]);
|
|
24364
24706
|
return { charges: raw.items, chargesPart: stampPart("contract_charges", raw, chargesCond) };
|
|
24365
24707
|
}
|
|
24366
|
-
async function fetchBlocks(ctx,
|
|
24367
|
-
if (!
|
|
24708
|
+
async function fetchBlocks(ctx, root3) {
|
|
24709
|
+
if (!root3.isBlockHours) {
|
|
24368
24710
|
return skipPart(
|
|
24369
|
-
|
|
24711
|
+
root3.contractTypeKnown ? `skipped: not a Block Hours contract (contractType ${root3.contractType} "${root3.contractTypeLabel}") \u2014 included hours apply to hour blocks only (zero wire)` : `skipped: the contract type is unknown (contractType ${root3.contractType || "absent"}; label unresolved) \u2014 included hours are not evaluable (zero wire)`
|
|
24370
24712
|
);
|
|
24371
24713
|
}
|
|
24372
24714
|
const blocksCond = [{ field: "contractID", op: "eq", value: ctx.id }];
|
|
24373
24715
|
const raw = await ctx.readPart("/V1.0/ContractBlocks/query", blocksCond, ["id", "datePurchased", "startDate", "endDate", "hours", "hoursApproved", "status", "isPaid"]);
|
|
24374
24716
|
return stampPart("contract_blocks", raw, blocksCond);
|
|
24375
24717
|
}
|
|
24376
|
-
async function fetchContractState(ctx,
|
|
24718
|
+
async function fetchContractState(ctx, root3) {
|
|
24377
24719
|
const servicesCond = [{ field: "contractID", op: "eq", value: ctx.id }];
|
|
24378
24720
|
const unitsCond = [{ field: "contractID", op: "eq", value: ctx.id }, ...ctx.windowOn("startDate")];
|
|
24379
24721
|
const roleCostsCond = [{ field: "contractID", op: "eq", value: ctx.id }];
|
|
@@ -24384,7 +24726,7 @@ async function fetchContractState(ctx, root2) {
|
|
|
24384
24726
|
() => fetchCharges(ctx),
|
|
24385
24727
|
() => ctx.readPart("/V1.0/ContractRoleCosts/query", roleCostsCond, ["id", "rate", "resourceID", "roleID"]),
|
|
24386
24728
|
() => ctx.readPart("/V1.0/ContractRates/query", ratesCond, ["id", "roleID", "contractHourlyRate", "internalCurrencyContractHourlyRate"]),
|
|
24387
|
-
() => fetchBlocks(ctx,
|
|
24729
|
+
() => fetchBlocks(ctx, root3)
|
|
24388
24730
|
]);
|
|
24389
24731
|
return { servicesRaw, servicesCond, unitRows: units.rows, unitsPartRaw: units.part, chargesPart, charges, roleCostsRaw, roleCostsCond, ratesRaw, ratesCond, blocksPart };
|
|
24390
24732
|
}
|
|
@@ -24749,7 +25091,7 @@ async function fetchSubscriptionsJoin(ctx) {
|
|
|
24749
25091
|
|
|
24750
25092
|
// src/resources/special/contracts/profitability.data.ts
|
|
24751
25093
|
async function gather(ctx) {
|
|
24752
|
-
const
|
|
25094
|
+
const root3 = await fetchRoot(ctx);
|
|
24753
25095
|
const stages = Object.fromEntries(
|
|
24754
25096
|
["state", "billing", "time", "activity", "open", "res", "join", "subs"].map((name) => [name, forkFetchCtx(ctx)])
|
|
24755
25097
|
);
|
|
@@ -24760,7 +25102,7 @@ async function gather(ctx) {
|
|
|
24760
25102
|
let openRead;
|
|
24761
25103
|
const openTask = () => openRead ??= fetchOpenTickets(stages.open);
|
|
24762
25104
|
const tasks = {
|
|
24763
|
-
state: () => fetchContractState(stages.state,
|
|
25105
|
+
state: () => fetchContractState(stages.state, root3),
|
|
24764
25106
|
billing: () => fetchBilling(stages.billing),
|
|
24765
25107
|
time: timeTask,
|
|
24766
25108
|
activity: activityTask,
|
|
@@ -24779,7 +25121,7 @@ async function gather(ctx) {
|
|
|
24779
25121
|
const completed = await mapReadTasks(ctx.http, order, async (name) => [name, await tasks[name]()]);
|
|
24780
25122
|
const parts = Object.fromEntries(completed);
|
|
24781
25123
|
mergeFetchContexts(ctx, Object.values(stages));
|
|
24782
|
-
return { root:
|
|
25124
|
+
return { root: root3, ...parts };
|
|
24783
25125
|
}
|
|
24784
25126
|
function stampListParts(v, f) {
|
|
24785
25127
|
const { state: state2, activity, join } = f;
|
|
@@ -27644,7 +27986,7 @@ async function fullProfile2(resource, id, opts = {}) {
|
|
|
27644
27986
|
const serviceLimit = compositePartLimit(opts.serviceLimit, "serviceLimit", OP12);
|
|
27645
27987
|
const billingRuleLimit = compositePartLimit(opts.billingRuleLimit, "billingRuleLimit", OP12);
|
|
27646
27988
|
const contractId = parseIdentifier(id, "id");
|
|
27647
|
-
const
|
|
27989
|
+
const root3 = await invokeRead(client, "contracts.get", [contractId]);
|
|
27648
27990
|
const [services, billingRules, charges, units] = await readTasks(resource.http, [
|
|
27649
27991
|
() => compositePart(client, "contract_services.query", [
|
|
27650
27992
|
{ filter: [{ field: "contractID", op: "eq", value: contractId }], limit: serviceLimit }
|
|
@@ -27660,7 +28002,7 @@ async function fullProfile2(resource, id, opts = {}) {
|
|
|
27660
28002
|
])
|
|
27661
28003
|
]);
|
|
27662
28004
|
return {
|
|
27663
|
-
root:
|
|
28005
|
+
root: root3,
|
|
27664
28006
|
parts: {
|
|
27665
28007
|
services,
|
|
27666
28008
|
billing_rules: billingRules,
|