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