node-autotask 0.86.0 → 0.87.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.
Files changed (38) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/MCP_TOOL_CATALOG.json +2 -2
  3. package/capabilities.json +175 -175
  4. package/dist/capabilities-data.js +174 -174
  5. package/dist/capabilities.cjs +4 -4
  6. package/dist/capabilities.js +1 -1
  7. package/dist/{chunk-YX6SSS4I.cjs → chunk-CUZJJCI5.cjs} +420 -219
  8. package/dist/{chunk-KYFJOIG4.js → chunk-EXNDYJPG.js} +3 -3
  9. package/dist/{chunk-DVD7RZIB.js → chunk-G57Q7OAC.js} +2 -2
  10. package/dist/{chunk-ELZTECDS.js → chunk-GAFG7RHG.js} +415 -214
  11. package/dist/{chunk-23LTWBKP.cjs → chunk-HUA4WB4N.cjs} +30 -30
  12. package/dist/{chunk-AZ54RMQR.js → chunk-NXSQXXNK.js} +2 -2
  13. package/dist/{chunk-SZ33SCCI.cjs → chunk-RU4ECNQN.cjs} +200 -200
  14. package/dist/{chunk-EYRQUMA2.cjs → chunk-YVNGUGG6.cjs} +3 -3
  15. package/dist/{index-B3zO78nP.d.ts → index-CsL5gGJo.d.ts} +8 -8
  16. package/dist/{index-CIgmz8qI.d.cts → index-Cxfr_DOD.d.cts} +8 -2
  17. package/dist/{index-CIgmz8qI.d.ts → index-Cxfr_DOD.d.ts} +8 -2
  18. package/dist/{index-C2p8D2mZ.d.cts → index-DGiua9uK.d.cts} +8 -8
  19. package/dist/index.cjs +84 -84
  20. package/dist/index.d.cts +3 -3
  21. package/dist/index.d.ts +3 -3
  22. package/dist/index.js +5 -5
  23. package/dist/operations/index.cjs +51 -51
  24. package/dist/operations/index.d.cts +4 -4
  25. package/dist/operations/index.d.ts +4 -4
  26. package/dist/operations/index.js +2 -2
  27. package/dist/pool.cjs +12 -12
  28. package/dist/pool.d.cts +1 -1
  29. package/dist/pool.d.ts +1 -1
  30. package/dist/pool.js +4 -4
  31. package/dist/resources/index.cjs +27 -27
  32. package/dist/resources/index.d.cts +2 -2
  33. package/dist/resources/index.d.ts +2 -2
  34. package/dist/resources/index.js +3 -3
  35. package/dist/types/index.d.cts +1 -1
  36. package/dist/types/index.d.ts +1 -1
  37. package/docs/VENDOR-QUIRKS.md +34 -17
  38. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- import { loadCapabilityRecords } from './chunk-KYFJOIG4.js';
1
+ import { loadCapabilityRecords } from './chunk-EXNDYJPG.js';
2
2
  import { NoopLogger, REDACTED, deepMarkUntrusted, wrapUntrusted } from './chunk-7NKB4UXV.js';
3
3
  import { randomUUID, createHash } from 'crypto';
4
4
  import { AsyncLocalStorage } from 'async_hooks';
@@ -1692,13 +1692,13 @@ function normalizeInCondition(cond, path) {
1692
1692
  return items === cond.items ? cond : { ...cond, items };
1693
1693
  }
1694
1694
  if (cond.op !== "in" && cond.op !== "notIn" || typeof cond.value !== "string") return cond;
1695
- const tokens = cond.value.split(",").map((t) => t.trim()).filter((t) => t.length > 0);
1696
- if (tokens.length === 0) {
1695
+ const tokens2 = cond.value.split(",").map((t) => t.trim()).filter((t) => t.length > 0);
1696
+ if (tokens2.length === 0) {
1697
1697
  throw new AutotaskConfigError(
1698
1698
  `Operator "${cond.op}" at ${path} has an empty value list \u2014 pass an array or a comma-separated string with at least one value (e.g. "1,2,3")`
1699
1699
  );
1700
1700
  }
1701
- const value = cond.udf === true ? tokens : tokens.map((t) => /^(0|[1-9]\d*)$/.test(t) && Number.isSafeInteger(Number(t)) ? Number(t) : t);
1701
+ const value = cond.udf === true ? tokens2 : tokens2.map((t) => /^(0|[1-9]\d*)$/.test(t) && Number.isSafeInteger(Number(t)) ? Number(t) : t);
1702
1702
  return { ...cond, value };
1703
1703
  }
1704
1704
  function refusedFilterShape(filter) {
@@ -19053,6 +19053,210 @@ async function expandResourceNames(client, ids2, opts = {}) {
19053
19053
  return { results, resolved, blind, failed };
19054
19054
  }
19055
19055
 
19056
+ // src/resources/special/_shared/numbers.ts
19057
+ function num(v) {
19058
+ return typeof v === "number" && Number.isFinite(v) ? v : 0;
19059
+ }
19060
+
19061
+ // src/resources/special/_shared/finance.ts
19062
+ function budgetExceededError(operation, message, details, suggestedAction) {
19063
+ return new AutotaskError(message, { code: "BUDGET_EXCEEDED", category: "policy", operation, details, suggestedAction });
19064
+ }
19065
+ function makeCallBudget(budget, onExceed) {
19066
+ let spent = 0;
19067
+ return {
19068
+ spend() {
19069
+ if (spent >= budget) throw onExceed(spent);
19070
+ spent += 1;
19071
+ },
19072
+ spent: () => spent
19073
+ };
19074
+ }
19075
+ function countingHttp(raw, spend) {
19076
+ const http = Object.create(raw);
19077
+ http.request = (o) => {
19078
+ spend();
19079
+ return raw.request(o);
19080
+ };
19081
+ return http;
19082
+ }
19083
+ function idChunks(ids2, size) {
19084
+ const out = [];
19085
+ for (let i = 0; i < ids2.length; i += size) out.push(ids2.slice(i, i + size));
19086
+ return out;
19087
+ }
19088
+ async function fetchIdChunks(http, entityPath, ids2, fields, operation, opts) {
19089
+ const chunkSize = opts?.chunkSize ?? 250;
19090
+ const out = /* @__PURE__ */ new Map();
19091
+ for (const chunk of idChunks(ids2, chunkSize)) {
19092
+ opts?.budgetSpend?.();
19093
+ const chunkKeys = new Set(chunk.map((id) => String(id)));
19094
+ try {
19095
+ const req = buildQueryRequest(http.baseUrl, entityPath, {
19096
+ filter: [{ field: "id", op: "in", value: chunk }],
19097
+ maxRecords: opts?.maxRecords ?? chunkSize,
19098
+ includeFields: fields
19099
+ });
19100
+ const res = await http.request({ ...req, operation });
19101
+ const { items: rows } = unwrapItems(res, operation);
19102
+ for (const row of rows) {
19103
+ const k = String(row["id"]);
19104
+ if (!chunkKeys.has(k)) continue;
19105
+ out.set(k, row);
19106
+ }
19107
+ } catch (err) {
19108
+ if (opts?.onChunkFault?.(chunk, err) !== true) throw err;
19109
+ }
19110
+ }
19111
+ return out;
19112
+ }
19113
+ function internalAmount(row, internalKey, localKey) {
19114
+ const v = row[internalKey];
19115
+ return typeof v === "number" && Number.isFinite(v) ? v : num(row[localKey]);
19116
+ }
19117
+ function toCents(v) {
19118
+ return Math.round(num(v) * 100);
19119
+ }
19120
+ async function readPicklists(http, entityPath, operation) {
19121
+ const res = await http.request({ method: "GET", path: `${entityPath}/entityInformation/fields`, operation });
19122
+ const body = typeof res === "object" && res !== null ? res : {};
19123
+ const fields = Array.isArray(body["fields"]) ? body["fields"] : [];
19124
+ const out = /* @__PURE__ */ new Map();
19125
+ for (const f of fields) {
19126
+ if (f["isPickList"] !== true || typeof f["name"] !== "string" || !Array.isArray(f["picklistValues"])) continue;
19127
+ const values = /* @__PURE__ */ new Map();
19128
+ for (const p of f["picklistValues"]) {
19129
+ const id = typeof p["value"] === "string" ? Number.parseInt(p["value"], 10) : Number.NaN;
19130
+ if (Number.isFinite(id)) values.set(id, String(p["label"] ?? ""));
19131
+ }
19132
+ out.set(f["name"], values);
19133
+ }
19134
+ return out;
19135
+ }
19136
+ function resolveSelector(operation, name, sel, values) {
19137
+ const out = /* @__PURE__ */ new Map();
19138
+ const misses = [];
19139
+ for (const s of sel) {
19140
+ const hits = typeof s === "number" ? values.has(s) ? [s] : [] : [...values].filter(([, l]) => l.trim().toLowerCase() === s.trim().toLowerCase()).map(([id]) => id);
19141
+ if (hits.length === 0) misses.push(JSON.stringify(s));
19142
+ for (const h of hits) out.set(h, values.get(h));
19143
+ }
19144
+ if (misses.length > 0) throw selectorUnmatched(operation, name, `${misses.join(", ")} matched no live value`, values);
19145
+ return out;
19146
+ }
19147
+ function selectorUnmatched(operation, name, what, values) {
19148
+ const live = [...values].map(([id, l]) => `${id} ${l}`).join("; ") || "(the picklist serves no values)";
19149
+ return new AutotaskConfigError(`${shortName(operation)}: ${name}: ${what}. Live values (id label): ${live}`, {
19150
+ operation,
19151
+ suggestedAction: `Pass ${name} as ids or exact labels from the live list.`
19152
+ });
19153
+ }
19154
+ var TENANT_HOURLY_LIMIT = 1e4;
19155
+ function tenantHourlyShare(calls) {
19156
+ return `${(calls / TENANT_HOURLY_LIMIT * 100).toFixed(2)}% of ${TENANT_HOURLY_LIMIT.toLocaleString("en-US")}/h`;
19157
+ }
19158
+ var isPosInt = (v) => Number.isSafeInteger(v) && v > 0;
19159
+ function checkIdList(name, v, max, problems, opts) {
19160
+ const ok = opts?.allowZero ? (x) => x === 0 || isPosInt(x) : isPosInt;
19161
+ if (!Array.isArray(v) || v.length === 0 || v.length > max || !v.every(ok)) {
19162
+ problems.push(`${name} must be a non-empty array of at most ${max} ${opts?.allowZero ? "non-negative" : "positive"} integer ids`);
19163
+ return void 0;
19164
+ }
19165
+ return [...new Set(v)].sort((a, b) => a - b);
19166
+ }
19167
+ function checkSelector(name, v, problems) {
19168
+ if (v === void 0) return void 0;
19169
+ if (!Array.isArray(v) || v.length === 0 || !v.every((x) => isPosInt(x) || typeof x === "string" && x.trim() !== "")) {
19170
+ problems.push(`${name} must be a non-empty array of picklist ids or labels`);
19171
+ return void 0;
19172
+ }
19173
+ return v;
19174
+ }
19175
+ function checkInt(name, v, def, max, problems) {
19176
+ if (v === void 0) return def;
19177
+ if (!Number.isInteger(v) || v < 1 || v > max) {
19178
+ problems.push(`${name} must be an integer 1..${max} (got ${String(v)})`);
19179
+ return def;
19180
+ }
19181
+ return v;
19182
+ }
19183
+ async function collectRows(res, filter, includeFields, page) {
19184
+ const out = [];
19185
+ for await (const r of res.query({ filter, includeFields, maxRecords: page, names: false })) out.push(r);
19186
+ return out;
19187
+ }
19188
+ function blindCountError(operation, subject, suggestedAction) {
19189
+ return new AutotaskError(`${shortName(operation)}: a gate count came back blind (unknown, not zero); ${subject} cannot be sized`, {
19190
+ code: "INVALID_RESPONSE",
19191
+ category: "server",
19192
+ operation,
19193
+ details: { reason: "blind_count" },
19194
+ suggestedAction
19195
+ });
19196
+ }
19197
+ function countMismatchError(operation, what, streamed, counted, rows) {
19198
+ const rowNote = rows !== void 0 && rows !== streamed ? ` (${rows} rows)` : "";
19199
+ return new AutotaskError(`${shortName(operation)}: the ${what} stream returned ${streamed} distinct ids${rowNote} but the gate count was ${counted} (the data changed mid-walk or a page dropped rows); the fold was discarded`, {
19200
+ code: "INVALID_RESPONSE",
19201
+ category: "server",
19202
+ operation,
19203
+ details: { reason: "count_mismatch", stream: what, streamed, counted },
19204
+ suggestedAction: "Retry the call."
19205
+ });
19206
+ }
19207
+ function compareIds(a, b) {
19208
+ for (let i = 0; i < a.length; i++) {
19209
+ const x = a[i] ?? null;
19210
+ const y = b[i] ?? null;
19211
+ if (x === y) continue;
19212
+ if (x === null) return -1;
19213
+ if (y === null) return 1;
19214
+ if (typeof x === "number" && typeof y === "number") return x - y;
19215
+ return String(x) < String(y) ? -1 : 1;
19216
+ }
19217
+ return 0;
19218
+ }
19219
+ var sortedRecord = (m) => Object.fromEntries([...m].sort((a, b) => a[0] - b[0]).map(([id, l]) => [String(id), l]));
19220
+ var shortName = (operation) => operation.split(".").pop() ?? operation;
19221
+
19222
+ // src/operations/nameBatch.ts
19223
+ var NAME_BATCH_CHUNK_SIZE = 250;
19224
+ function nameEntryKey(path) {
19225
+ return path + "\0name";
19226
+ }
19227
+ function nameEntrySnapshot(cache, path) {
19228
+ const value = cache?.get(nameEntryKey(path));
19229
+ if (value === void 0 || value === null || typeof value !== "object") return void 0;
19230
+ return () => value;
19231
+ }
19232
+ async function batchNameReads(http, entityPath, ids2, fields, operation) {
19233
+ const cache = http.readCache;
19234
+ const epoch = cache?.epoch ?? 0;
19235
+ const out = /* @__PURE__ */ new Map();
19236
+ const rows = await fetchIdChunks(http, entityPath, ids2, fields, operation, {
19237
+ chunkSize: NAME_BATCH_CHUNK_SIZE,
19238
+ maxRecords: NAME_BATCH_CHUNK_SIZE,
19239
+ onChunkFault: (chunk, err) => {
19240
+ if (!isAutotaskError(err) || err.code === "ABORTED") return false;
19241
+ const error = err.httpStatus !== void 0 ? { code: err.code, message: err.message, httpStatus: err.httpStatus } : { code: err.code, message: err.message };
19242
+ for (const id of chunk) out.set(String(id), { kind: "error", error });
19243
+ return true;
19244
+ }
19245
+ });
19246
+ for (const id of ids2) {
19247
+ const k = String(id);
19248
+ if (out.has(k)) continue;
19249
+ const record = rows.get(k);
19250
+ if (record === void 0) {
19251
+ out.set(k, { kind: "unreadable" });
19252
+ continue;
19253
+ }
19254
+ cache?.set(nameEntryKey(`${entityPath}/${k}`), record, epoch);
19255
+ out.set(k, { kind: "record", record });
19256
+ }
19257
+ return out;
19258
+ }
19259
+
19056
19260
  // src/operations/lineOfBusinessChain.ts
19057
19261
  function vendorId(value) {
19058
19262
  if (typeof value === "number") return Number.isSafeInteger(value) && value >= 1 ? value : void 0;
@@ -19133,7 +19337,7 @@ async function resolveLineOfBusinessChain(http, associationId, options) {
19133
19337
 
19134
19338
  // src/operations/compositeNames.ts
19135
19339
  var PICKLIST_VALUE_NOT_SERVED_NOTE = "The picklist is served to this API user, but this record's value is not in it (an inactive or unexposed value) \u2014 the label cannot be resolved and is null; refreshing the field catalog will not surface it. (A picklist the vendor does not expose at all is reported with the field-catalog honesty note instead.)";
19136
- var DEFAULT_MAX_NAME_READS = 20;
19340
+ var DEFAULT_MAX_NAME_READS = 50;
19137
19341
  var TICKET_LABEL_FIELDS = ["status", "priority", "ticketType", "issueType", "subIssueType", "source", "queueID"];
19138
19342
  function isVendorId(value) {
19139
19343
  if (typeof value === "number") return Number.isSafeInteger(value) && value >= 0;
@@ -19226,6 +19430,15 @@ var FK_NAME_FIELD = {
19226
19430
  product: "name",
19227
19431
  configurationItemCategory: "name"
19228
19432
  };
19433
+ var FK_BATCH_FIELDS = {
19434
+ role: ["name"],
19435
+ billingCode: ["name"],
19436
+ contract: ["contractName"],
19437
+ company: ["companyName"],
19438
+ ticket: ["ticketNumber", "title"],
19439
+ product: ["name"],
19440
+ configurationItemCategory: ["name"]
19441
+ };
19229
19442
  function fkName(record, table) {
19230
19443
  if (table === "ticket") {
19231
19444
  const parts = [record["ticketNumber"], record["title"]].filter((v) => typeof v === "string" && v.trim() !== "").map((v) => v.trim());
@@ -19250,6 +19463,8 @@ async function resolveCompositeNames(http, plan, opts = {}) {
19250
19463
  const readCache = http.readCache;
19251
19464
  const section = { truncated: false, rows: {}, reasons: {} };
19252
19465
  let remaining = budget;
19466
+ let overBudget = 0;
19467
+ let unreadable = 0;
19253
19468
  const tasks = [];
19254
19469
  let contractLobPointer;
19255
19470
  let contractLobUnread;
@@ -19266,6 +19481,7 @@ async function resolveCompositeNames(http, plan, opts = {}) {
19266
19481
  for (const id of overBudgetResource) {
19267
19482
  section.rows[`resource:${id}`] = { name: null, blind: false };
19268
19483
  section.truncated = true;
19484
+ overBudget += 1;
19269
19485
  }
19270
19486
  const overSet = new Set(overBudgetResource.map((id) => String(id)));
19271
19487
  const opIds = plan.resourceIds.filter((id) => !overSet.has(String(id)));
@@ -19275,6 +19491,7 @@ async function resolveCompositeNames(http, plan, opts = {}) {
19275
19491
  for (const id of pass.slice(500)) {
19276
19492
  section.rows[`resource:${id}`] = { name: null, blind: false };
19277
19493
  section.truncated = true;
19494
+ overBudget += 1;
19278
19495
  }
19279
19496
  pass = pass.slice(0, 500);
19280
19497
  }
@@ -19303,48 +19520,89 @@ async function resolveCompositeNames(http, plan, opts = {}) {
19303
19520
  product: client.products,
19304
19521
  configurationItemCategory: client.configurationItemCategories
19305
19522
  };
19523
+ const isLobContract = (fk2) => fk2.table === "contract" && plan.lineOfBusinessContractId !== void 0 && String(fk2.id) === String(plan.lineOfBusinessContractId);
19524
+ const fkRows = /* @__PURE__ */ new Map();
19525
+ const takeLobPointer = (fk2, record) => {
19526
+ if (plan.lineOfBusinessId === void 0 && isLobContract(fk2)) contractLobPointer = vendorId(record["organizationalLevelAssociationID"]);
19527
+ };
19528
+ const steps = [];
19529
+ const coldByTable = /* @__PURE__ */ new Map();
19306
19530
  for (const fk2 of plan.recordFks) {
19307
19531
  const key = `${fk2.table}:${fk2.id}`;
19308
- const snapshot = nameRecordSnapshot(readCache, `${FK_TABLE_PATH[fk2.table]}/${fk2.id}`, fk2.id, FK_GET_OPERATION[fk2.table]);
19309
- const cold = snapshot === void 0;
19310
- if (cold) {
19311
- if (remaining < 1) {
19312
- tasks.push(async () => () => {
19313
- section.rows[key] = { name: null, blind: false };
19314
- });
19315
- section.truncated = true;
19316
- if (fk2.table === "contract" && plan.lineOfBusinessContractId !== void 0 && String(fk2.id) === String(plan.lineOfBusinessContractId)) {
19317
- contractLobUnread = "capped";
19318
- }
19319
- continue;
19320
- }
19321
- remaining -= 1;
19532
+ const path = `${FK_TABLE_PATH[fk2.table]}/${fk2.id}`;
19533
+ const snapshot = nameRecordSnapshot(readCache, path, fk2.id, FK_GET_OPERATION[fk2.table]) ?? (isLobContract(fk2) ? void 0 : nameEntrySnapshot(readCache, path));
19534
+ if (snapshot !== void 0) {
19535
+ steps.push({ fk: fk2, snapshot });
19536
+ continue;
19537
+ }
19538
+ if (remaining < 1) {
19539
+ fkRows.set(key, { name: null, blind: false });
19540
+ overBudget += 1;
19541
+ section.truncated = true;
19542
+ if (isLobContract(fk2)) contractLobUnread = "capped";
19543
+ continue;
19544
+ }
19545
+ remaining -= 1;
19546
+ steps.push({ fk: fk2 });
19547
+ if (!isLobContract(fk2)) coldByTable.set(fk2.table, [...coldByTable.get(fk2.table) ?? [], fk2]);
19548
+ }
19549
+ const batched = /* @__PURE__ */ new Set();
19550
+ for (const { fk: fk2, snapshot } of steps) {
19551
+ const key = `${fk2.table}:${fk2.id}`;
19552
+ if (snapshot !== void 0) {
19553
+ tasks.push(async () => {
19554
+ const row = await fkRow(fk2, async () => snapshot());
19555
+ return () => {
19556
+ fkRows.set(key, row);
19557
+ };
19558
+ });
19559
+ continue;
19322
19560
  }
19561
+ const group = isLobContract(fk2) ? void 0 : coldByTable.get(fk2.table);
19562
+ if (group === void 0 || group.length === 1) {
19563
+ tasks.push(async () => {
19564
+ const row = await fkRow(fk2, async () => await holders[fk2.table].get(fk2.id));
19565
+ return () => {
19566
+ fkRows.set(key, row);
19567
+ };
19568
+ });
19569
+ continue;
19570
+ }
19571
+ if (batched.has(fk2.table)) continue;
19572
+ batched.add(fk2.table);
19573
+ const table = fk2.table;
19323
19574
  tasks.push(async () => {
19324
- let row;
19325
- try {
19326
- const record = snapshot !== void 0 ? snapshot() : await holders[fk2.table].get(fk2.id);
19327
- if (fk2.table === "contract" && plan.lineOfBusinessId === void 0 && plan.lineOfBusinessContractId !== void 0 && String(fk2.id) === String(plan.lineOfBusinessContractId)) {
19328
- contractLobPointer = vendorId(record["organizationalLevelAssociationID"]);
19329
- }
19330
- row = { name: fkName(record, fk2.table), blind: false };
19331
- } catch (err) {
19332
- if (err instanceof NotFoundError) {
19333
- row = { name: null, blind: true };
19334
- } else if (isAutotaskError(err) && err.code !== "ABORTED") {
19335
- row = { name: null, blind: false, error: faultRow(err) };
19336
- if (fk2.table === "contract" && plan.lineOfBusinessContractId !== void 0 && String(fk2.id) === String(plan.lineOfBusinessContractId)) {
19337
- contractLobUnread = "unresolved";
19575
+ const outcomes = await batchNameReads(http, FK_TABLE_PATH[table], group.map((g) => g.id), FK_BATCH_FIELDS[table], FK_GET_OPERATION[table].replace(/\.get$/, ".query"));
19576
+ return () => {
19577
+ for (const g of group) {
19578
+ const out = outcomes.get(String(g.id));
19579
+ const gKey = `${table}:${g.id}`;
19580
+ if (out.kind === "record") fkRows.set(gKey, { name: fkName(out.record, table), blind: false });
19581
+ else if (out.kind === "error") fkRows.set(gKey, { name: null, blind: false, error: out.error });
19582
+ else {
19583
+ fkRows.set(gKey, { name: null, blind: true, unreadable: true });
19584
+ unreadable += 1;
19338
19585
  }
19339
- } else {
19340
- throw err;
19341
19586
  }
19342
- }
19343
- return () => {
19344
- section.rows[key] = row;
19345
19587
  };
19346
19588
  });
19347
19589
  }
19590
+ async function fkRow(fk2, read) {
19591
+ try {
19592
+ const record = await read();
19593
+ takeLobPointer(fk2, record);
19594
+ return { name: fkName(record, fk2.table), blind: false };
19595
+ } catch (err) {
19596
+ if (err instanceof NotFoundError) {
19597
+ return { name: null, blind: true };
19598
+ }
19599
+ if (isAutotaskError(err) && err.code !== "ABORTED") {
19600
+ if (isLobContract(fk2)) contractLobUnread = "unresolved";
19601
+ return { name: null, blind: false, error: faultRow(err) };
19602
+ }
19603
+ throw err;
19604
+ }
19605
+ }
19348
19606
  let picklists = null;
19349
19607
  if (plan.labelFields.length > 0) {
19350
19608
  tasks.push(async () => {
@@ -19358,6 +19616,10 @@ async function resolveCompositeNames(http, plan, opts = {}) {
19358
19616
  });
19359
19617
  }
19360
19618
  for (const merge of await readTasks(http, tasks)) merge();
19619
+ for (const fk2 of plan.recordFks) {
19620
+ const key = `${fk2.table}:${fk2.id}`;
19621
+ section.rows[key] = fkRows.get(key);
19622
+ }
19361
19623
  let lineOfBusiness2 = null;
19362
19624
  const lobId = plan.lineOfBusinessId ?? contractLobPointer;
19363
19625
  if (lobId !== void 0) {
@@ -19382,6 +19644,8 @@ async function resolveCompositeNames(http, plan, opts = {}) {
19382
19644
  return {
19383
19645
  section,
19384
19646
  lineOfBusiness: lineOfBusiness2,
19647
+ overBudget,
19648
+ unreadable,
19385
19649
  resourceName: (id) => section.rows[`resource:${id}`]?.name ?? null,
19386
19650
  recordName: (table, id) => section.rows[`${table}:${id}`]?.name ?? null,
19387
19651
  labelFor: (field, value) => {
@@ -19998,11 +20262,13 @@ async function labelRows(client, resourceKey, rows) {
19998
20262
  }
19999
20263
  return r;
20000
20264
  });
20001
- const capHit = names?.section.truncated === true;
20265
+ const overBudget = names?.overBudget ?? 0;
20266
+ const unreadable = names?.unreadable ?? 0;
20002
20267
  const unresolved2 = Object.keys(names?.section.reasons ?? {});
20003
- if (capHit === false && unresolved2.length === 0) return { rows: out };
20268
+ if (overBudget === 0 && unreadable === 0 && unresolved2.length === 0) return { rows: out };
20004
20269
  const parts = [];
20005
- if (capHit) parts.push(`ids left unlabelled (their *Name is null): the per-call cap of ${DEFAULT_MAX_NAME_READS} uncached name reads was hit \u2014 names already read are cached, so repeating or narrowing the call labels more`);
20270
+ if (overBudget > 0) parts.push(`ids left unlabelled (their *Name is null): ${overBudget} id(s) over the per-call cap of ${DEFAULT_MAX_NAME_READS} uncached name reads \u2014 names already read are cached, so repeating or narrowing the call labels more`);
20271
+ if (unreadable > 0) parts.push(`${unreadable} id(s) not returned by the batched name read (their *Name is null): the record may be absent or not visible to this API user, so this is not a not-found`);
20006
20272
  if (unresolved2.length > 0) parts.push(`picklist label(s) unavailable for ${unresolved2.join(", ")} (see reasons)`);
20007
20273
  return { rows: out, names: { note: parts.join("; "), ...Object.keys(names.section.reasons).length > 0 ? { reasons: names.section.reasons } : {} } };
20008
20274
  }
@@ -20223,7 +20489,7 @@ var QueryBase = class {
20223
20489
  * (as queryBounded). Label siblings are opt-in (issue #287): the per-call
20224
20490
  * `names` key is the explicit override, absent = the client's `labels`
20225
20491
  * option (off by default). When on, labelling runs per page, so the cold
20226
- * name-read cap (20) applies per page; a capped id gets a null `*Name`
20492
+ * name-read cap (DEFAULT_MAX_NAME_READS) applies per page; a capped id gets a null `*Name`
20227
20493
  * (an iterator has no result envelope for the `names` summary). A
20228
20494
  * resource built without a client (bare `HttpClient`) yields raw rows.
20229
20495
  */
@@ -22141,6 +22407,93 @@ function admitTaskNote(data, parentId, creating) {
22141
22407
  if (!creating && !Object.keys(body).some((key) => key !== "id" && key !== "itemId")) fail3("update must contain a writable field");
22142
22408
  }
22143
22409
 
22410
+ // src/operations/invoke/fieldSuggest.ts
22411
+ var MAX_SUGGESTIONS = 3;
22412
+ var MIN_SUBSTRING_CHARS = 4;
22413
+ var GENERIC_TOKENS = /* @__PURE__ */ new Set(["date", "time", "datetime", "day", "is", "number", "type", "name", "last", "on", "at", "id"]);
22414
+ var DATE_TOKENS = /* @__PURE__ */ new Set(["date", "time", "datetime", "day", "on", "at"]);
22415
+ var TOKEN_SYNONYMS = [["install", "purchase", "purchased"]];
22416
+ var SYNONYM_OF = new Map(TOKEN_SYNONYMS.flatMap((group) => group.map((t) => [t, group[0]])));
22417
+ var Tier = { Substring: 0, Tokens: 1, Edit: 2, Generic: 3, SameType: 4, Rest: 5 };
22418
+ function tokens(name) {
22419
+ return (name.match(/[A-Z]?[a-z]+|[A-Z]+(?![a-z])|\d+/g) ?? []).map((t) => t.toLowerCase());
22420
+ }
22421
+ function normalTokens(name) {
22422
+ return new Set(tokens(name).map((t) => SYNONYM_OF.get(t) ?? t));
22423
+ }
22424
+ function editDistance(a, b, cap = Number.POSITIVE_INFINITY) {
22425
+ if (Math.abs(a.length - b.length) > cap) return cap + 1;
22426
+ const far = Number.isFinite(cap) ? cap + 1 : a.length + b.length + 1;
22427
+ const band = Number.isFinite(cap) ? cap : a.length + b.length;
22428
+ let prev2 = new Int32Array(b.length + 1).fill(far);
22429
+ let prev = Int32Array.from({ length: b.length + 1 }, (_, j) => j <= band ? j : far);
22430
+ let cur = new Int32Array(b.length + 1).fill(far);
22431
+ for (let i = 1; i <= a.length; i += 1) {
22432
+ const lo = Math.max(1, i - band);
22433
+ const hi = Math.min(b.length, i + band);
22434
+ cur.fill(far);
22435
+ cur[0] = i <= band ? i : far;
22436
+ let rowMin = cur[0];
22437
+ for (let j = lo; j <= hi; j += 1) {
22438
+ const cost = a[i - 1] === b[j - 1] ? 0 : 1;
22439
+ let v = Math.min(prev[j] + 1, cur[j - 1] + 1, prev[j - 1] + cost);
22440
+ if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) v = Math.min(v, prev2[j - 2] + 1);
22441
+ cur[j] = v;
22442
+ if (v < rowMin) rowMin = v;
22443
+ }
22444
+ if (rowMin > cap) return cap + 1;
22445
+ [prev2, prev, cur] = [prev, cur, prev2];
22446
+ }
22447
+ return Math.min(prev[b.length], cap + 1);
22448
+ }
22449
+ function looksLikeDate(name) {
22450
+ return tokens(name).some((t) => DATE_TOKENS.has(t));
22451
+ }
22452
+ var MAX_EDITS = 6;
22453
+ var DISTANCE_CAP = 8;
22454
+ function score(unknown, candidate2) {
22455
+ const u = unknown.lower;
22456
+ const c = candidate2.lower;
22457
+ const [shorter, longer] = u.length <= c.length ? [u, c] : [c, u];
22458
+ let shared = 0;
22459
+ let meaningful = 0;
22460
+ for (const t of candidate2.tokens) {
22461
+ if (!unknown.tokens.has(t)) continue;
22462
+ shared += 1;
22463
+ if (!GENERIC_TOKENS.has(t)) meaningful += 1;
22464
+ }
22465
+ const threshold = Math.min(MAX_EDITS, Math.max(1, Math.floor(longer.length * 0.3)));
22466
+ const distance = editDistance(u, c, DISTANCE_CAP);
22467
+ const shorterGeneric = shorter === u ? unknown.allGeneric : [...candidate2.tokens].every((t) => GENERIC_TOKENS.has(t));
22468
+ if (shorter.length >= MIN_SUBSTRING_CHARS && longer.includes(shorter) && !shorterGeneric) return { tier: Tier.Substring, shared, distance };
22469
+ if (meaningful > 0) return { tier: Tier.Tokens, shared, distance };
22470
+ if (shorter.length >= 3 && distance <= threshold) return { tier: Tier.Edit, shared, distance };
22471
+ if (shared > 0) return { tier: Tier.Generic, shared, distance };
22472
+ if (candidate2.isDate && unknown.isDate) return { tier: Tier.SameType, shared, distance };
22473
+ return { tier: Tier.Rest, shared, distance };
22474
+ }
22475
+ var better = (a, b) => a.tier - b.tier || b.shared - a.shared || a.distance - b.distance;
22476
+ var isClose = (s) => s.tier <= Tier.Edit;
22477
+ function rankFieldNames(unknown, known, dateFields = []) {
22478
+ const dates = new Set(dateFields);
22479
+ const candidates = known.map((name) => ({ name, lower: name.toLowerCase(), tokens: normalTokens(name), isDate: dates.has(name) }));
22480
+ const best = /* @__PURE__ */ new Map();
22481
+ const suggestions = [];
22482
+ for (const name of new Set(unknown)) {
22483
+ const probeTokens = normalTokens(name);
22484
+ const probe = { lower: name.toLowerCase(), tokens: probeTokens, isDate: looksLikeDate(name), allGeneric: [...probeTokens].every((t) => GENERIC_TOKENS.has(t)) };
22485
+ const scored = candidates.map((c, index) => ({ k: c.name, index, s: score(probe, c) }));
22486
+ for (const { k, s } of scored) {
22487
+ const prev = best.get(k);
22488
+ if (prev === void 0 || better(s, prev) < 0) best.set(k, s);
22489
+ }
22490
+ const close = scored.filter((x) => isClose(x.s)).sort((a, b) => better(a.s, b.s) || a.index - b.index);
22491
+ if (close.length > 0) suggestions.push({ name, candidates: close.slice(0, MAX_SUGGESTIONS).map((x) => x.k) });
22492
+ }
22493
+ const ordered = known.map((k, index) => ({ k, index, s: best.get(k) ?? { tier: Tier.Rest, shared: 0, distance: 0 } })).sort((a, b) => a.s.tier === Tier.Rest && b.s.tier === Tier.Rest ? a.index - b.index : better(a.s, b.s) || a.index - b.index).map((x) => x.k);
22494
+ return { ordered, suggestions };
22495
+ }
22496
+
22144
22497
  // src/operations/invoke/fieldNames.ts
22145
22498
  async function liveFieldNames(holder) {
22146
22499
  if (holder === void 0) return null;
@@ -22156,6 +22509,14 @@ async function liveFieldNames(holder) {
22156
22509
  var UNKNOWN_NAME_LIST_CAP = 20;
22157
22510
  var UNKNOWN_NAME_DISPLAY_CHARS = 40;
22158
22511
  var ENTITY_NAME_LIST_CAP = 20;
22512
+ var REFUSAL_MAX_CHARS = 3e3;
22513
+ var SUGGESTED_NAME_CAP = 5;
22514
+ function didYouMeanClause(suggestions, take = SUGGESTED_NAME_CAP) {
22515
+ const shown = suggestions.slice(0, take);
22516
+ if (shown.length === 0) return "";
22517
+ const cut = (n) => n.length > UNKNOWN_NAME_DISPLAY_CHARS ? `${n.slice(0, UNKNOWN_NAME_DISPLAY_CHARS)}\u2026` : n;
22518
+ return ` \u2014 did you mean: ${shown.map((s) => `"${cut(s.name)}" -> ${s.candidates.map(cut).join(", ")}`).join("; ")}`;
22519
+ }
22159
22520
  function formatUnknownNameList(names, cap = UNKNOWN_NAME_LIST_CAP) {
22160
22521
  const listed = names.slice(0, cap).map((n) => `"${n.length > UNKNOWN_NAME_DISPLAY_CHARS ? `${n.slice(0, UNKNOWN_NAME_DISPLAY_CHARS)}\u2026` : n}"`).join(", ");
22161
22522
  const more = names.length > cap ? ` (and ${names.length - cap} more)` : "";
@@ -22238,10 +22599,16 @@ function unknownNamesRefusal(record, authority, known, unknownInclude, unknownFi
22238
22599
  if (unknownInclude.length > 0) parts.push(`includeFields has unknown field name(s) ${formatUnknownNameList(unknownInclude)}`);
22239
22600
  if (unknownFilter.length > 0) parts.push(`filter condition(s) carry unknown field name(s) ${formatUnknownNameList(unknownFilter)}`);
22240
22601
  const wireClause = record.operation === "count" ? "the count request was not issued" : "the query POST was not issued";
22241
- const head = `invoke: "${record.id}" ${parts.join("; ")} against ${authority}`;
22602
+ const base = `invoke: "${record.id}" ${parts.join("; ")} against ${authority}`;
22603
+ const ranked = [...unknownInclude.slice(0, UNKNOWN_NAME_LIST_CAP), ...unknownFilter.slice(0, UNKNOWN_NAME_LIST_CAP)];
22604
+ const { ordered, suggestions } = rankFieldNames(ranked, known, MODEL_DATE_FIELDS[record.resource]);
22242
22605
  const count = known.length > ENTITY_NAME_LIST_CAP ? `${known.length}, first ${ENTITY_NAME_LIST_CAP}` : `${known.length}`;
22243
- const withList = `${head} \u2014 fields available on ${record.resource} (${count}): ${formatUnknownNameList(known, ENTITY_NAME_LIST_CAP)} \u2014 ${wireClause}`;
22244
- const message = known.length === 0 ? `${head} \u2014 ${wireClause}` : withList.length <= 3e3 ? withList : `${head} \u2014 ${record.resource} has ${known.length} fields; use operations.fieldCatalog resources: ["${record.resource}"] for the full set \u2014 ${wireClause}`;
22606
+ const pointer = `${record.resource} has ${known.length} fields; use operations.fieldCatalog resources: ["${record.resource}"] for the full set`;
22607
+ let take = SUGGESTED_NAME_CAP;
22608
+ while (take > 0 && `${base}${didYouMeanClause(suggestions, take)} \u2014 ${pointer} \u2014 ${wireClause}`.length > REFUSAL_MAX_CHARS) take -= 1;
22609
+ const head = `${base}${didYouMeanClause(suggestions, take)}`;
22610
+ const withList = `${head} \u2014 fields available on ${record.resource} (${count}): ${formatUnknownNameList(ordered, ENTITY_NAME_LIST_CAP)} \u2014 ${wireClause}`;
22611
+ const message = known.length === 0 ? `${head} \u2014 ${wireClause}` : withList.length <= REFUSAL_MAX_CHARS ? withList : `${head} \u2014 ${pointer} \u2014 ${wireClause}`;
22245
22612
  return new AutotaskConfigError(
22246
22613
  message,
22247
22614
  {
@@ -24306,7 +24673,7 @@ var GenericResource = class extends BaseResource {
24306
24673
  /** Get the record with its primary context records in one call (each part a
24307
24674
  * single-record fetch; no sub-lists; absent/dangling references come back null).
24308
24675
  * `names: true` (projects) adds the opt-in name siblings + the top-level `names`
24309
- * section; `maxNameReads` may lower the name-read budget (default 20), never raise it. */
24676
+ * section; `maxNameReads` may lower the name-read budget (default 50), never raise it. */
24310
24677
  async getContext(id, opts = {}) {
24311
24678
  this.requireHelper("getContext");
24312
24679
  const cfg = this.config;
@@ -24479,7 +24846,7 @@ function prepare(query, opts) {
24479
24846
  function companyPieces(terms) {
24480
24847
  return textFragments(terms);
24481
24848
  }
24482
- function score(record, terms, source) {
24849
+ function score2(record, terms, source) {
24483
24850
  const match = scoreTerms(terms, companyTerms(record.companyName ?? ""));
24484
24851
  return match === void 0 ? void 0 : { record, source, ...match };
24485
24852
  }
@@ -24509,7 +24876,7 @@ async function searchFuzzy(resource, query, opts = {}) {
24509
24876
  const validIndex = index?.revision() === revision;
24510
24877
  for (const row of validIndex ? indexed : []) if (typeof row.id === "number") merged.set(row.id, { row, source: "index" });
24511
24878
  for (const row of live) if (typeof row.id === "number") merged.set(row.id, { row: slimCompany(row), source: merged.has(row.id) ? "both" : "live" });
24512
- const ranked = [...merged.values()].filter(({ row }) => opts.includeInactive || row.isActive === true).map(({ row, source }) => score(row, terms, source)).filter((row) => row !== void 0).sort((a, b) => compareTermScores(a, b) || Number(b.record.isActive === true) - Number(a.record.isActive === true) || (a.record.id ?? 0) - (b.record.id ?? 0));
24879
+ const ranked = [...merged.values()].filter(({ row }) => opts.includeInactive || row.isActive === true).map(({ row, source }) => score2(row, terms, source)).filter((row) => row !== void 0).sort((a, b) => compareTermScores(a, b) || Number(b.record.isActive === true) - Number(a.record.isActive === true) || (a.record.id ?? 0) - (b.record.id ?? 0));
24513
24880
  const items = ranked.slice(0, limit);
24514
24881
  if (opts.includeFamily) {
24515
24882
  const records = await addCompanyFamilies(resource.http, items.map((row) => row.record), "companies.searchFuzzy");
@@ -24982,11 +25349,6 @@ function monthsBefore(date, months) {
24982
25349
  return new Date(Date.UTC(y, m - 1 - months, Math.min(d, lastDay))).toISOString().slice(0, 10);
24983
25350
  }
24984
25351
 
24985
- // src/resources/special/_shared/numbers.ts
24986
- function num(v) {
24987
- return typeof v === "number" && Number.isFinite(v) ? v : 0;
24988
- }
24989
-
24990
25352
  // src/resources/special/companies/shared.ts
24991
25353
  var DEFAULT_LIMIT = 25;
24992
25354
  var MAX_LIMIT = 500;
@@ -26276,167 +26638,6 @@ async function aggregate(client, operation, filter, opts = {}) {
26276
26638
  return result;
26277
26639
  }
26278
26640
 
26279
- // src/resources/special/_shared/finance.ts
26280
- function budgetExceededError(operation, message, details, suggestedAction) {
26281
- return new AutotaskError(message, { code: "BUDGET_EXCEEDED", category: "policy", operation, details, suggestedAction });
26282
- }
26283
- function makeCallBudget(budget, onExceed) {
26284
- let spent = 0;
26285
- return {
26286
- spend() {
26287
- if (spent >= budget) throw onExceed(spent);
26288
- spent += 1;
26289
- },
26290
- spent: () => spent
26291
- };
26292
- }
26293
- function countingHttp(raw, spend) {
26294
- const http = Object.create(raw);
26295
- http.request = (o) => {
26296
- spend();
26297
- return raw.request(o);
26298
- };
26299
- return http;
26300
- }
26301
- function idChunks(ids2, size) {
26302
- const out = [];
26303
- for (let i = 0; i < ids2.length; i += size) out.push(ids2.slice(i, i + size));
26304
- return out;
26305
- }
26306
- async function fetchIdChunks(http, entityPath, ids2, fields, operation, opts) {
26307
- const chunkSize = opts?.chunkSize ?? 250;
26308
- const out = /* @__PURE__ */ new Map();
26309
- for (const chunk of idChunks(ids2, chunkSize)) {
26310
- opts?.budgetSpend?.();
26311
- const chunkKeys = new Set(chunk.map((id) => String(id)));
26312
- try {
26313
- const req = buildQueryRequest(http.baseUrl, entityPath, {
26314
- filter: [{ field: "id", op: "in", value: chunk }],
26315
- maxRecords: opts?.maxRecords ?? chunkSize,
26316
- includeFields: fields
26317
- });
26318
- const res = await http.request({ ...req, operation });
26319
- const { items: rows } = unwrapItems(res, operation);
26320
- for (const row of rows) {
26321
- const k = String(row["id"]);
26322
- if (!chunkKeys.has(k)) continue;
26323
- out.set(k, row);
26324
- }
26325
- } catch (err) {
26326
- if (opts?.onChunkFault?.(chunk, err) !== true) throw err;
26327
- }
26328
- }
26329
- return out;
26330
- }
26331
- function internalAmount(row, internalKey, localKey) {
26332
- const v = row[internalKey];
26333
- return typeof v === "number" && Number.isFinite(v) ? v : num(row[localKey]);
26334
- }
26335
- function toCents(v) {
26336
- return Math.round(num(v) * 100);
26337
- }
26338
- async function readPicklists(http, entityPath, operation) {
26339
- const res = await http.request({ method: "GET", path: `${entityPath}/entityInformation/fields`, operation });
26340
- const body = typeof res === "object" && res !== null ? res : {};
26341
- const fields = Array.isArray(body["fields"]) ? body["fields"] : [];
26342
- const out = /* @__PURE__ */ new Map();
26343
- for (const f of fields) {
26344
- if (f["isPickList"] !== true || typeof f["name"] !== "string" || !Array.isArray(f["picklistValues"])) continue;
26345
- const values = /* @__PURE__ */ new Map();
26346
- for (const p of f["picklistValues"]) {
26347
- const id = typeof p["value"] === "string" ? Number.parseInt(p["value"], 10) : Number.NaN;
26348
- if (Number.isFinite(id)) values.set(id, String(p["label"] ?? ""));
26349
- }
26350
- out.set(f["name"], values);
26351
- }
26352
- return out;
26353
- }
26354
- function resolveSelector(operation, name, sel, values) {
26355
- const out = /* @__PURE__ */ new Map();
26356
- const misses = [];
26357
- for (const s of sel) {
26358
- const hits = typeof s === "number" ? values.has(s) ? [s] : [] : [...values].filter(([, l]) => l.trim().toLowerCase() === s.trim().toLowerCase()).map(([id]) => id);
26359
- if (hits.length === 0) misses.push(JSON.stringify(s));
26360
- for (const h of hits) out.set(h, values.get(h));
26361
- }
26362
- if (misses.length > 0) throw selectorUnmatched(operation, name, `${misses.join(", ")} matched no live value`, values);
26363
- return out;
26364
- }
26365
- function selectorUnmatched(operation, name, what, values) {
26366
- const live = [...values].map(([id, l]) => `${id} ${l}`).join("; ") || "(the picklist serves no values)";
26367
- return new AutotaskConfigError(`${shortName(operation)}: ${name}: ${what}. Live values (id label): ${live}`, {
26368
- operation,
26369
- suggestedAction: `Pass ${name} as ids or exact labels from the live list.`
26370
- });
26371
- }
26372
- var TENANT_HOURLY_LIMIT = 1e4;
26373
- function tenantHourlyShare(calls) {
26374
- return `${(calls / TENANT_HOURLY_LIMIT * 100).toFixed(2)}% of ${TENANT_HOURLY_LIMIT.toLocaleString("en-US")}/h`;
26375
- }
26376
- var isPosInt = (v) => Number.isSafeInteger(v) && v > 0;
26377
- function checkIdList(name, v, max, problems, opts) {
26378
- const ok = opts?.allowZero ? (x) => x === 0 || isPosInt(x) : isPosInt;
26379
- if (!Array.isArray(v) || v.length === 0 || v.length > max || !v.every(ok)) {
26380
- problems.push(`${name} must be a non-empty array of at most ${max} ${opts?.allowZero ? "non-negative" : "positive"} integer ids`);
26381
- return void 0;
26382
- }
26383
- return [...new Set(v)].sort((a, b) => a - b);
26384
- }
26385
- function checkSelector(name, v, problems) {
26386
- if (v === void 0) return void 0;
26387
- if (!Array.isArray(v) || v.length === 0 || !v.every((x) => isPosInt(x) || typeof x === "string" && x.trim() !== "")) {
26388
- problems.push(`${name} must be a non-empty array of picklist ids or labels`);
26389
- return void 0;
26390
- }
26391
- return v;
26392
- }
26393
- function checkInt(name, v, def, max, problems) {
26394
- if (v === void 0) return def;
26395
- if (!Number.isInteger(v) || v < 1 || v > max) {
26396
- problems.push(`${name} must be an integer 1..${max} (got ${String(v)})`);
26397
- return def;
26398
- }
26399
- return v;
26400
- }
26401
- async function collectRows(res, filter, includeFields, page) {
26402
- const out = [];
26403
- for await (const r of res.query({ filter, includeFields, maxRecords: page, names: false })) out.push(r);
26404
- return out;
26405
- }
26406
- function blindCountError(operation, subject, suggestedAction) {
26407
- return new AutotaskError(`${shortName(operation)}: a gate count came back blind (unknown, not zero); ${subject} cannot be sized`, {
26408
- code: "INVALID_RESPONSE",
26409
- category: "server",
26410
- operation,
26411
- details: { reason: "blind_count" },
26412
- suggestedAction
26413
- });
26414
- }
26415
- function countMismatchError(operation, what, streamed, counted, rows) {
26416
- const rowNote = rows !== void 0 && rows !== streamed ? ` (${rows} rows)` : "";
26417
- return new AutotaskError(`${shortName(operation)}: the ${what} stream returned ${streamed} distinct ids${rowNote} but the gate count was ${counted} (the data changed mid-walk or a page dropped rows); the fold was discarded`, {
26418
- code: "INVALID_RESPONSE",
26419
- category: "server",
26420
- operation,
26421
- details: { reason: "count_mismatch", stream: what, streamed, counted },
26422
- suggestedAction: "Retry the call."
26423
- });
26424
- }
26425
- function compareIds(a, b) {
26426
- for (let i = 0; i < a.length; i++) {
26427
- const x = a[i] ?? null;
26428
- const y = b[i] ?? null;
26429
- if (x === y) continue;
26430
- if (x === null) return -1;
26431
- if (y === null) return 1;
26432
- if (typeof x === "number" && typeof y === "number") return x - y;
26433
- return String(x) < String(y) ? -1 : 1;
26434
- }
26435
- return 0;
26436
- }
26437
- var sortedRecord = (m) => Object.fromEntries([...m].sort((a, b) => a[0] - b[0]).map(([id, l]) => [String(id), l]));
26438
- var shortName = (operation) => operation.split(".").pop() ?? operation;
26439
-
26440
26641
  // src/operations/fetchByIds.ts
26441
26642
  var FETCH_BY_IDS_MAX_ITEMS = 500;
26442
26643
  var FETCH_BY_IDS_CHUNK_SIZE = 250;