node-autotask 0.37.1 → 0.39.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 +31 -0
- package/MCP_TOOL_CATALOG.json +127 -44
- package/MCP_TOOL_MANIFEST.md +9 -9
- package/N8N_MCP_MANIFEST.json +4 -4
- package/N8N_MCP_MANIFEST.md +5 -5
- package/README.md +3 -0
- package/capabilities.json +2500 -1713
- package/capabilities.schema.json +2 -1
- package/dist/capabilities.cjs +2 -2
- package/dist/capabilities.d.cts +4 -4
- package/dist/capabilities.d.ts +4 -4
- package/dist/capabilities.js +1 -1
- package/dist/{chunk-KQ6HMBB4.js → chunk-2KQS3RHQ.js} +2499 -1712
- package/dist/{chunk-TBFXRNNE.cjs → chunk-45PLS73K.cjs} +2452 -2065
- package/dist/chunk-5VHSLJMR.js +71 -0
- package/dist/{chunk-PFFW4DIK.cjs → chunk-6ROB5KXB.cjs} +285 -285
- package/dist/{chunk-7IADHNBZ.js → chunk-FV5PJLIZ.js} +2602 -2215
- package/dist/{chunk-25VGFT5M.cjs → chunk-KSNK6UEW.cjs} +143 -143
- package/dist/{chunk-PFJAMFUL.js → chunk-LD5UPSDB.js} +2 -2
- package/dist/chunk-MJTKK3QG.cjs +71 -0
- package/dist/{chunk-7WI7FBPB.js → chunk-OKFTECIE.js} +2 -2
- package/dist/{chunk-HBYKTXN3.cjs → chunk-RAZEXOLC.cjs} +2499 -1712
- package/dist/{index-m-7fOwFl.d.cts → index-BQVStxwi.d.cts} +15 -1
- package/dist/{index-m-7fOwFl.d.ts → index-BQVStxwi.d.ts} +15 -1
- package/dist/{index-CqepIQfp.d.cts → index-BVOOHPvr.d.cts} +28 -8
- package/dist/{index-BDqw377y.d.ts → index-Bmoiwhx2.d.ts} +28 -8
- package/dist/index.cjs +27 -22
- package/dist/index.d.cts +26 -5
- package/dist/index.d.ts +26 -5
- package/dist/index.js +9 -4
- package/dist/operations/index.cjs +249 -227
- package/dist/operations/index.d.cts +76 -15
- package/dist/operations/index.d.ts +76 -15
- package/dist/operations/index.js +60 -38
- package/dist/pool.cjs +10 -9
- package/dist/pool.d.cts +2 -2
- package/dist/pool.d.ts +2 -2
- package/dist/pool.js +5 -4
- package/dist/resources/index.cjs +5 -4
- package/dist/resources/index.d.cts +2 -2
- package/dist/resources/index.d.ts +2 -2
- package/dist/resources/index.js +4 -3
- package/dist/types/index.d.cts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/untrusted.cjs +24 -70
- package/dist/untrusted.js +12 -58
- package/docs/API.md +129 -3
- package/examples/mcp/manifest.ts +5 -0
- package/examples/mcp/rank.ts +62 -0
- package/examples/mcp/tools-meta.ts +6 -1
- package/package.json +1 -1
|
@@ -64,29 +64,34 @@
|
|
|
64
64
|
|
|
65
65
|
|
|
66
66
|
|
|
67
|
-
var _chunkTBFXRNNEcjs = require('../chunk-TBFXRNNE.cjs');
|
|
68
67
|
|
|
69
68
|
|
|
70
|
-
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
var _chunk45PLS73Kcjs = require('../chunk-45PLS73K.cjs');
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
var _chunkRAZEXOLCcjs = require('../chunk-RAZEXOLC.cjs');
|
|
75
|
+
require('../chunk-MJTKK3QG.cjs');
|
|
71
76
|
|
|
72
77
|
// src/operations/searchAcrossResources.ts
|
|
73
78
|
var DEFAULT_LIMIT = 25;
|
|
74
79
|
function resourceFor(client, key) {
|
|
75
|
-
return client[
|
|
80
|
+
return client[_chunk45PLS73Kcjs.camelKey.call(void 0, key)];
|
|
76
81
|
}
|
|
77
82
|
async function searchAcrossResources(client, query, opts = {}) {
|
|
78
83
|
const text = query.trim();
|
|
79
84
|
if (text === "") {
|
|
80
|
-
throw new (0,
|
|
85
|
+
throw new (0, _chunk45PLS73Kcjs.AutotaskConfigError)("searchAcrossResources: query must be a non-empty string");
|
|
81
86
|
}
|
|
82
|
-
const keys = _nullishCoalesce(opts.resources, () => (
|
|
87
|
+
const keys = _nullishCoalesce(opts.resources, () => ( _chunk45PLS73Kcjs.WORKFLOW_RESOURCES));
|
|
83
88
|
if (keys.length === 0) {
|
|
84
|
-
throw new (0,
|
|
89
|
+
throw new (0, _chunk45PLS73Kcjs.AutotaskConfigError)("searchAcrossResources: no resources requested");
|
|
85
90
|
}
|
|
86
|
-
const limit =
|
|
91
|
+
const limit = _chunk45PLS73Kcjs.clampPageSize.call(void 0, _nullishCoalesce(opts.limit, () => ( DEFAULT_LIMIT)));
|
|
87
92
|
const totalLimit = opts.totalLimit;
|
|
88
93
|
if (totalLimit !== void 0 && !(Number.isInteger(totalLimit) && totalLimit >= 1)) {
|
|
89
|
-
throw new (0,
|
|
94
|
+
throw new (0, _chunk45PLS73Kcjs.AutotaskConfigError)("searchAcrossResources: totalLimit must be a positive integer");
|
|
90
95
|
}
|
|
91
96
|
const results = [];
|
|
92
97
|
const skipped = [];
|
|
@@ -117,7 +122,7 @@ async function searchAcrossResources(client, query, opts = {}) {
|
|
|
117
122
|
|
|
118
123
|
// src/operations/resolveAny.ts
|
|
119
124
|
function resourceFor2(client, key) {
|
|
120
|
-
return client[
|
|
125
|
+
return client[_chunk45PLS73Kcjs.camelKey.call(void 0, key)];
|
|
121
126
|
}
|
|
122
127
|
var FAULT_CATEGORIES = /* @__PURE__ */ new Set(["auth", "rate_limit", "server", "network", "timeout", "policy"]);
|
|
123
128
|
function missCost(identifier) {
|
|
@@ -126,13 +131,13 @@ function missCost(identifier) {
|
|
|
126
131
|
}
|
|
127
132
|
async function resolveAny(client, identifier, opts = {}) {
|
|
128
133
|
if (typeof identifier === "number") {
|
|
129
|
-
|
|
134
|
+
_chunk45PLS73Kcjs.parseIdentifier.call(void 0, identifier, "identifier");
|
|
130
135
|
} else if (identifier.trim() === "") {
|
|
131
|
-
throw new (0,
|
|
136
|
+
throw new (0, _chunk45PLS73Kcjs.AutotaskConfigError)("resolveAny: identifier must be non-empty");
|
|
132
137
|
}
|
|
133
|
-
const keys = _nullishCoalesce(opts.resources, () => (
|
|
138
|
+
const keys = _nullishCoalesce(opts.resources, () => ( _chunk45PLS73Kcjs.WORKFLOW_RESOURCES));
|
|
134
139
|
if (keys.length === 0) {
|
|
135
|
-
throw new (0,
|
|
140
|
+
throw new (0, _chunk45PLS73Kcjs.AutotaskConfigError)("resolveAny: no resources requested");
|
|
136
141
|
}
|
|
137
142
|
const results = [];
|
|
138
143
|
for (const key of keys) {
|
|
@@ -162,9 +167,9 @@ async function resolveAny(client, identifier, opts = {}) {
|
|
|
162
167
|
} catch (err) {
|
|
163
168
|
let code;
|
|
164
169
|
let candidates = [];
|
|
165
|
-
if (err instanceof
|
|
170
|
+
if (err instanceof _chunk45PLS73Kcjs.AutotaskConfigError) {
|
|
166
171
|
code = "CONFIG_ERROR";
|
|
167
|
-
} else if (
|
|
172
|
+
} else if (_chunk45PLS73Kcjs.isAutotaskError.call(void 0, err)) {
|
|
168
173
|
if (FAULT_CATEGORIES.has(err.category)) throw err;
|
|
169
174
|
code = err.code;
|
|
170
175
|
if (code === "RESOLUTION_AMBIGUOUS" && err.resourceIds !== void 0) {
|
|
@@ -191,7 +196,7 @@ async function resolveAny(client, identifier, opts = {}) {
|
|
|
191
196
|
// src/operations/aggregate.ts
|
|
192
197
|
var AGGREGATE_TOP_MAX = 100;
|
|
193
198
|
var AGGREGATE_DEFAULT_TOP = 25;
|
|
194
|
-
var AGGREGATE_DEFAULT_LIMIT =
|
|
199
|
+
var AGGREGATE_DEFAULT_LIMIT = _chunk45PLS73Kcjs.BOUNDED_QUERY_MAX_LIMIT;
|
|
195
200
|
var AGGREGATE_DATE_BUCKETS = ["month", "week", "year"];
|
|
196
201
|
var DATE_ONLY_RE = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
197
202
|
var DATETIME_RE = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(\.\d{1,9})?(Z|[+-]\d{2}:?\d{2})?$/;
|
|
@@ -248,10 +253,10 @@ function dateBucketLabel(value, bucket) {
|
|
|
248
253
|
}
|
|
249
254
|
var QUERY_RESOURCE_KEYS = (() => {
|
|
250
255
|
const s = /* @__PURE__ */ new Set();
|
|
251
|
-
for (const rec of
|
|
256
|
+
for (const rec of _chunkRAZEXOLCcjs.CAPABILITIES) if (rec.operation === "query") s.add(rec.resource);
|
|
252
257
|
return s;
|
|
253
258
|
})();
|
|
254
|
-
var AGGREGATE_OPT_KEYS = ["groupBy", "sum", "top", "limit"];
|
|
259
|
+
var AGGREGATE_OPT_KEYS = ["groupBy", "sum", "top", "limit", "names"];
|
|
255
260
|
var OP_RE = /^([a-z0-9_]+)\.query$/;
|
|
256
261
|
function num2(v) {
|
|
257
262
|
return typeof v === "number" && Number.isFinite(v) ? v : 0;
|
|
@@ -284,15 +289,15 @@ function parseFilterConditions(filter, problems) {
|
|
|
284
289
|
return [];
|
|
285
290
|
}
|
|
286
291
|
try {
|
|
287
|
-
return
|
|
292
|
+
return _chunk45PLS73Kcjs.buildFilter.call(void 0, conds).filter;
|
|
288
293
|
} catch (err) {
|
|
289
|
-
problems.push(err instanceof
|
|
294
|
+
problems.push(err instanceof _chunk45PLS73Kcjs.AutotaskConfigError ? err.message : `filter must be the query-bag filter (13 operators; caps 500 OR-conditions / 1 UDF / 8000 chars); ${String(err)}`);
|
|
290
295
|
return [];
|
|
291
296
|
}
|
|
292
297
|
}
|
|
293
298
|
function checkOptsBag(opts, problems) {
|
|
294
299
|
if (opts !== void 0 && (typeof opts !== "object" || opts === null || Array.isArray(opts))) {
|
|
295
|
-
throw new (0,
|
|
300
|
+
throw new (0, _chunk45PLS73Kcjs.AutotaskConfigError)(
|
|
296
301
|
`aggregate: opts must be the options object (got ${Array.isArray(opts) ? "an array" : typeof opts})`,
|
|
297
302
|
{ operation: "operations.aggregate" }
|
|
298
303
|
);
|
|
@@ -302,50 +307,34 @@ function checkOptsBag(opts, problems) {
|
|
|
302
307
|
problems.push(`unknown opts key "${key}" \u2014 the bag is closed: ${AGGREGATE_OPT_KEYS.join(", ")}`);
|
|
303
308
|
}
|
|
304
309
|
}
|
|
310
|
+
if (_optionalChain([opts, 'optionalAccess', _2 => _2.names]) !== void 0 && typeof opts.names !== "boolean") problems.push(`names must be a boolean (got ${typeof opts.names})`);
|
|
305
311
|
}
|
|
306
|
-
function checkSumFields(name, fields,
|
|
312
|
+
function checkSumFields(name, fields, problems) {
|
|
307
313
|
if (fields === void 0) return [];
|
|
308
314
|
if (!Array.isArray(fields) || fields.length === 0 || fields.some((f) => typeof f !== "string" || f.trim() === "")) {
|
|
309
315
|
problems.push(`${name} must be a non-empty array of exact vendor field names (discover them via operations.fieldCatalog)`);
|
|
310
316
|
return [];
|
|
311
317
|
}
|
|
312
|
-
|
|
313
|
-
for (const f of fields) {
|
|
314
|
-
if (oracles.fieldSets === void 0 || !oracles.fieldSets.includes(f)) {
|
|
315
|
-
problems.push(`${name}: "${f}" is not a field of ${oracles.resourceKey} \u2014 a hallucinated field is a shape error, not a silent fold-miss (exact vendor field names via operations.fieldCatalog)`);
|
|
316
|
-
} else {
|
|
317
|
-
out.push(f);
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
return out;
|
|
318
|
+
return fields;
|
|
321
319
|
}
|
|
322
|
-
function parseGroupSpec(f, oracles, problems) {
|
|
323
|
-
const { resourceKey,
|
|
320
|
+
function parseGroupSpec(f, oracles, known, problems) {
|
|
321
|
+
const { resourceKey, dateSets } = oracles;
|
|
324
322
|
const at = f.indexOf("@");
|
|
325
|
-
if (at === -1) {
|
|
326
|
-
if (fieldSets === void 0 || !fieldSets.includes(f)) {
|
|
327
|
-
problems.push(`groupBy: "${f}" is not a field of ${resourceKey} \u2014 a hallucinated field is a shape error, not a silent fold-miss (exact vendor field names via operations.fieldCatalog)`);
|
|
328
|
-
return void 0;
|
|
329
|
-
}
|
|
330
|
-
return { name: f, base: f };
|
|
331
|
-
}
|
|
323
|
+
if (at === -1) return { name: f, base: f };
|
|
332
324
|
const base = f.slice(0, at);
|
|
333
325
|
const suffix = f.slice(at + 1);
|
|
334
326
|
if (!AGGREGATE_DATE_BUCKETS.includes(suffix)) {
|
|
335
327
|
problems.push(`groupBy: "${f}": unknown bucket suffix "${suffix}" \u2014 the closed set is month | week | year (the suffix applies to date-typed fields only)`);
|
|
336
328
|
return void 0;
|
|
337
329
|
}
|
|
338
|
-
if (
|
|
339
|
-
problems.push(`groupBy: "${f}": "${base}" is not a field of ${resourceKey} \u2014 a hallucinated field is a shape error, not a silent fold-miss (exact vendor field names via operations.fieldCatalog)`);
|
|
340
|
-
return void 0;
|
|
341
|
-
}
|
|
330
|
+
if (known !== void 0 && !known.includes(base)) return void 0;
|
|
342
331
|
if (dateSets === void 0 || !dateSets.includes(base)) {
|
|
343
332
|
problems.push(`groupBy: "${f}": "${base}" is not a date field of ${resourceKey} (the @month/@week/@year bucket suffix applies to date-typed fields of the resource's vendored model \u2014 exact vendor field names via operations.fieldCatalog)`);
|
|
344
333
|
return void 0;
|
|
345
334
|
}
|
|
346
335
|
return { name: f, base, bucket: suffix };
|
|
347
336
|
}
|
|
348
|
-
function parseGroupBy(opts, oracles, problems) {
|
|
337
|
+
function parseGroupBy(opts, oracles, known, problems) {
|
|
349
338
|
const groupBy = [];
|
|
350
339
|
if (opts.groupBy === void 0) return groupBy;
|
|
351
340
|
if (!Array.isArray(opts.groupBy) || opts.groupBy.length === 0 || opts.groupBy.some((f) => typeof f !== "string" || f.trim() === "")) {
|
|
@@ -353,7 +342,7 @@ function parseGroupBy(opts, oracles, problems) {
|
|
|
353
342
|
return groupBy;
|
|
354
343
|
}
|
|
355
344
|
for (const f of opts.groupBy) {
|
|
356
|
-
const spec = parseGroupSpec(f, oracles, problems);
|
|
345
|
+
const spec = parseGroupSpec(f, oracles, known, problems);
|
|
357
346
|
if (spec !== void 0) groupBy.push(spec);
|
|
358
347
|
}
|
|
359
348
|
return groupBy;
|
|
@@ -372,26 +361,49 @@ function parseTopAndLimit(opts, problems) {
|
|
|
372
361
|
if (!Number.isInteger(opts.limit)) {
|
|
373
362
|
problems.push(`limit must be an integer (got ${String(opts.limit)})`);
|
|
374
363
|
} else {
|
|
375
|
-
limit = Math.min(Math.max(opts.limit, 1),
|
|
364
|
+
limit = Math.min(Math.max(opts.limit, 1), _chunk45PLS73Kcjs.BOUNDED_QUERY_MAX_LIMIT);
|
|
376
365
|
}
|
|
377
366
|
}
|
|
378
367
|
return { top, limit };
|
|
379
368
|
}
|
|
380
|
-
function
|
|
369
|
+
async function checkFieldNames(resourceKey, conditions, opts, problems) {
|
|
370
|
+
const record = resourceKey === void 0 ? void 0 : _chunkRAZEXOLCcjs.CAPABILITIES.find((r) => r.resource === resourceKey && r.operation === "query");
|
|
371
|
+
if (record === void 0) return void 0;
|
|
372
|
+
const strings = (v) => Array.isArray(v) ? v.filter((f) => typeof f === "string" && f.trim() !== "") : [];
|
|
373
|
+
const groupBy = strings(opts.groupBy);
|
|
374
|
+
const found = await _chunk45PLS73Kcjs.findUnknownFieldNames.call(void 0, record, void 0, {
|
|
375
|
+
filter: _chunk45PLS73Kcjs.collectFilterFieldNames.call(void 0, conditions),
|
|
376
|
+
groupBy: groupBy.map((f) => f.split("@")[0]),
|
|
377
|
+
sum: strings(opts.sum)
|
|
378
|
+
});
|
|
379
|
+
if (found === void 0) return void 0;
|
|
380
|
+
const refuse2 = (key, entry, base) => {
|
|
381
|
+
const named = entry === base ? `"${base}"` : `"${entry}": "${base}"`;
|
|
382
|
+
problems.push(`${key}: ${named} is not a field of ${resourceKey} \u2014 a hallucinated field is a shape error, not a silent fold-miss (exact vendor field names via operations.fieldCatalog; checked against ${found.authority})`);
|
|
383
|
+
};
|
|
384
|
+
for (const f of found.unknown["filter"]) refuse2("filter", f, f);
|
|
385
|
+
for (const f of groupBy) {
|
|
386
|
+
const base = f.split("@")[0];
|
|
387
|
+
if (found.unknown["groupBy"].includes(base)) refuse2("groupBy", f, base);
|
|
388
|
+
}
|
|
389
|
+
for (const f of found.unknown["sum"]) refuse2("sum", f, f);
|
|
390
|
+
return found.known;
|
|
391
|
+
}
|
|
392
|
+
async function validateAggregate(operation, filter, opts) {
|
|
381
393
|
const problems = [];
|
|
382
394
|
const resourceKey = parseOperationKey(operation, problems);
|
|
383
395
|
const conditions = parseFilterConditions(filter, problems);
|
|
384
396
|
checkOptsBag(opts, problems);
|
|
385
397
|
const oracles = {
|
|
386
398
|
resourceKey,
|
|
387
|
-
|
|
388
|
-
dateSets: resourceKey !== void 0 ? _chunkTBFXRNNEcjs.MODEL_DATE_FIELDS[resourceKey] : void 0
|
|
399
|
+
dateSets: resourceKey !== void 0 ? _chunk45PLS73Kcjs.MODEL_DATE_FIELDS[resourceKey] : void 0
|
|
389
400
|
};
|
|
390
|
-
const
|
|
391
|
-
const
|
|
401
|
+
const known = await checkFieldNames(resourceKey, conditions, opts, problems);
|
|
402
|
+
const groupBy = parseGroupBy(opts, oracles, known, problems);
|
|
403
|
+
const sum = checkSumFields("sum", opts.sum, problems);
|
|
392
404
|
const { top, limit } = parseTopAndLimit(opts, problems);
|
|
393
405
|
if (problems.length > 0) {
|
|
394
|
-
throw new (0,
|
|
406
|
+
throw new (0, _chunk45PLS73Kcjs.AutotaskConfigError)(
|
|
395
407
|
`aggregate: ${problems.length} problem(s) found pre-request (zero wire was issued)
|
|
396
408
|
- ` + problems.join("\n- "),
|
|
397
409
|
{ operation: "operations.aggregate" }
|
|
@@ -424,10 +436,10 @@ function foldGroups(items, v) {
|
|
|
424
436
|
return [...groups.values()].sort((a, b) => b.count - a.count || (a.keyOrder < b.keyOrder ? -1 : a.keyOrder > b.keyOrder ? 1 : 0));
|
|
425
437
|
}
|
|
426
438
|
async function aggregate(client, operation, filter, opts = {}) {
|
|
427
|
-
const v = validateAggregate(operation, filter, opts);
|
|
428
|
-
const holder = client[
|
|
439
|
+
const v = await validateAggregate(operation, filter, opts);
|
|
440
|
+
const holder = client[_chunk45PLS73Kcjs.camelKey.call(void 0, v.resourceKey)];
|
|
429
441
|
if (holder === void 0) {
|
|
430
|
-
throw new (0,
|
|
442
|
+
throw new (0, _chunk45PLS73Kcjs.AutotaskConfigError)(`aggregate: the client exposes no accessor for resource "${v.resourceKey}"`, {
|
|
431
443
|
operation: "operations.aggregate",
|
|
432
444
|
suggestedAction: "Rebuild the client from the SDK build that ships this registry (the resource set is pinned by the plan)."
|
|
433
445
|
});
|
|
@@ -444,9 +456,10 @@ async function aggregate(client, operation, filter, opts = {}) {
|
|
|
444
456
|
const res = await holder.queryBounded({ filter: wireFilter, limit: v.limit });
|
|
445
457
|
const sorted = foldGroups(res.items, v);
|
|
446
458
|
const top = sorted.slice(0, v.top);
|
|
459
|
+
const labelled = opts.names === false || v.groupBy.length === 0 ? void 0 : await _chunk45PLS73Kcjs.labelRows.call(void 0, client, v.resourceKey, top.map((g) => g.key));
|
|
447
460
|
const result = {
|
|
448
461
|
mode: v.groupBy.length > 0 ? "group" : "sum",
|
|
449
|
-
groups: top.map((g) => ({ key: g.key, count: g.count, ...g.sums !== void 0 ? { sums: g.sums } : {} })),
|
|
462
|
+
groups: top.map((g, i) => ({ key: _nullishCoalesce(_optionalChain([labelled, 'optionalAccess', _3 => _3.rows, 'access', _4 => _4[i]]), () => ( g.key)), count: g.count, ...g.sums !== void 0 ? { sums: g.sums } : {} })),
|
|
450
463
|
totalGroups: sorted.length,
|
|
451
464
|
groupsTruncated: sorted.length > top.length,
|
|
452
465
|
totalScanned: res.fetched,
|
|
@@ -454,6 +467,8 @@ async function aggregate(client, operation, filter, opts = {}) {
|
|
|
454
467
|
};
|
|
455
468
|
if (res.blindSurface !== void 0) result.blindSurface = res.blindSurface;
|
|
456
469
|
if (res.emptyReason !== void 0) result.emptyReason = res.emptyReason;
|
|
470
|
+
if (res.relationNote !== void 0) result.relationNote = res.relationNote;
|
|
471
|
+
if (_optionalChain([labelled, 'optionalAccess', _5 => _5.names]) !== void 0) result.names = labelled.names;
|
|
457
472
|
return result;
|
|
458
473
|
}
|
|
459
474
|
|
|
@@ -472,12 +487,12 @@ var DEFAULT_CONTRACT_TYPE_RE = /^\s*(recurring|fixed)\b/i;
|
|
|
472
487
|
var CONTRACTS_PATH = "/V1.0/Contracts";
|
|
473
488
|
var COMPANIES_PATH = "/V1.0/Companies";
|
|
474
489
|
var BILLING_ITEMS_PATH = "/V1.0/BillingItems";
|
|
475
|
-
var LINE_TYPE_FIELDS = ["billingItemType", "timeEntryID", "expenseItemID", ...
|
|
476
|
-
var isLabour = (line) =>
|
|
490
|
+
var LINE_TYPE_FIELDS = ["billingItemType", "timeEntryID", "expenseItemID", ..._chunk45PLS73Kcjs.CHARGE_LINE_FKS, ..._chunk45PLS73Kcjs.SERVICE_LINE_FKS];
|
|
491
|
+
var isLabour = (line) => _chunk45PLS73Kcjs.billingLineType.call(void 0, line) === "labour";
|
|
477
492
|
function picklistKey(c, dim, path, field, raw, missing) {
|
|
478
|
-
const id =
|
|
493
|
+
const id = _chunk45PLS73Kcjs.num.call(void 0, raw);
|
|
479
494
|
if (id === 0) return { id: null, label: missing };
|
|
480
|
-
const label = _optionalChain([c, 'access',
|
|
495
|
+
const label = _optionalChain([c, 'access', _6 => _6.labels, 'access', _7 => _7[path], 'optionalAccess', _8 => _8.get, 'call', _9 => _9(field), 'optionalAccess', _10 => _10.get, 'call', _11 => _11(id)]);
|
|
481
496
|
if (label === void 0) {
|
|
482
497
|
c.unlabelled.add(`${dim}: ${field} value ${id} has no label on the live ${path} picklist (id-only)`);
|
|
483
498
|
return { id };
|
|
@@ -488,7 +503,7 @@ var DIMENSIONS = {
|
|
|
488
503
|
vertical: {
|
|
489
504
|
joins: { companies: ["marketSegmentID"] },
|
|
490
505
|
picklist: COMPANIES_PATH,
|
|
491
|
-
key: (c) => picklistKey(c, "vertical", COMPANIES_PATH, "marketSegmentID", _optionalChain([c, 'access',
|
|
506
|
+
key: (c) => picklistKey(c, "vertical", COMPANIES_PATH, "marketSegmentID", _optionalChain([c, 'access', _12 => _12.company, 'optionalAccess', _13 => _13["marketSegmentID"]]), "unassigned")
|
|
492
507
|
},
|
|
493
508
|
contractType: {
|
|
494
509
|
key: (c) => picklistKey(c, "contractType", CONTRACTS_PATH, "contractType", c.contract["contractType"], "none")
|
|
@@ -498,7 +513,7 @@ var DIMENSIONS = {
|
|
|
498
513
|
},
|
|
499
514
|
company: {
|
|
500
515
|
joins: { companies: ["companyName"] },
|
|
501
|
-
key: (c) => ({ id:
|
|
516
|
+
key: (c) => ({ id: _chunk45PLS73Kcjs.num.call(void 0, c.line["companyID"]), name: String(_nullishCoalesce(_optionalChain([c, 'access', _14 => _14.company, 'optionalAccess', _15 => _15["companyName"]]), () => ( ""))) })
|
|
502
517
|
},
|
|
503
518
|
month: {
|
|
504
519
|
key: (c) => ({ id: c.invoice.month })
|
|
@@ -506,11 +521,11 @@ var DIMENSIONS = {
|
|
|
506
521
|
billingItemKind: {
|
|
507
522
|
lineFields: LINE_TYPE_FIELDS,
|
|
508
523
|
picklist: BILLING_ITEMS_PATH,
|
|
509
|
-
key: (c) =>
|
|
524
|
+
key: (c) => _chunk45PLS73Kcjs.num.call(void 0, c.line["billingItemType"]) === 0 ? { id: _chunk45PLS73Kcjs.billingLineType.call(void 0, c.line), label: _chunk45PLS73Kcjs.billingLineType.call(void 0, c.line) } : picklistKey(c, "billingItemKind", BILLING_ITEMS_PATH, "billingItemType", c.line["billingItemType"], "other")
|
|
510
525
|
},
|
|
511
526
|
contract: {
|
|
512
527
|
joins: { contracts: ["contractName"] },
|
|
513
|
-
key: (c) => ({ id:
|
|
528
|
+
key: (c) => ({ id: _chunk45PLS73Kcjs.num.call(void 0, c.line["contractID"]), name: String(_nullishCoalesce(c.contract["contractName"], () => ( ""))) })
|
|
514
529
|
},
|
|
515
530
|
// Per line (no contract-pointer fallback): association → level2 (the Line of Business, `name`) + level1 (the division).
|
|
516
531
|
lineOfBusiness: {
|
|
@@ -518,11 +533,11 @@ var DIMENSIONS = {
|
|
|
518
533
|
joins: { organizationalLevelAssociations: [], organizationalLevel1s: [], organizationalLevel2s: [] },
|
|
519
534
|
unresolved: "unresolvedAssociations",
|
|
520
535
|
key: (c) => {
|
|
521
|
-
const id =
|
|
536
|
+
const id = _chunk45PLS73Kcjs.num.call(void 0, c.line["organizationalLevelAssociationID"]);
|
|
522
537
|
if (id === 0) return { id: null, label: "no LOB assigned" };
|
|
523
538
|
const a = c.joined.organizationalLevelAssociations.get(id);
|
|
524
|
-
const l1 = c.joined.organizationalLevel1s.get(
|
|
525
|
-
const l2 = c.joined.organizationalLevel2s.get(
|
|
539
|
+
const l1 = c.joined.organizationalLevel1s.get(_chunk45PLS73Kcjs.num.call(void 0, _optionalChain([a, 'optionalAccess', _16 => _16["organizationalLevel1ID"]])));
|
|
540
|
+
const l2 = c.joined.organizationalLevel2s.get(_chunk45PLS73Kcjs.num.call(void 0, _optionalChain([a, 'optionalAccess', _17 => _17["organizationalLevel2ID"]])));
|
|
526
541
|
if (l1 === void 0 || l2 === void 0) return "unresolvedAssociations";
|
|
527
542
|
return { id, name: String(_nullishCoalesce(l2["name"], () => ( ""))), division: String(_nullishCoalesce(l1["name"], () => ( ""))) };
|
|
528
543
|
}
|
|
@@ -533,9 +548,9 @@ var DIMENSIONS = {
|
|
|
533
548
|
joins: { timeEntries: [], resources: [] },
|
|
534
549
|
unresolved: "unresolvedTimeEntries",
|
|
535
550
|
key: (c) => {
|
|
536
|
-
const te =
|
|
551
|
+
const te = _chunk45PLS73Kcjs.num.call(void 0, c.line["timeEntryID"]);
|
|
537
552
|
if (!isLabour(c.line) || te === 0) return { id: null, label: "n/a" };
|
|
538
|
-
const id =
|
|
553
|
+
const id = _chunk45PLS73Kcjs.num.call(void 0, _optionalChain([c, 'access', _18 => _18.joined, 'access', _19 => _19.timeEntries, 'access', _20 => _20.get, 'call', _21 => _21(te), 'optionalAccess', _22 => _22["resourceID"]]));
|
|
539
554
|
const r = c.joined.resources.get(id);
|
|
540
555
|
if (r === void 0) return "unresolvedTimeEntries";
|
|
541
556
|
return { id, name: `${String(_nullishCoalesce(r["firstName"], () => ( "")))} ${String(_nullishCoalesce(r["lastName"], () => ( "")))}`.trim() };
|
|
@@ -546,58 +561,58 @@ var DIMENSIONS = {
|
|
|
546
561
|
joins: { billingCodes: [] },
|
|
547
562
|
unresolved: "unresolvedBillingCodes",
|
|
548
563
|
key: (c) => {
|
|
549
|
-
const id =
|
|
564
|
+
const id = _chunk45PLS73Kcjs.num.call(void 0, c.line["billingCodeID"]);
|
|
550
565
|
if (id === 0) return { id: null, label: "none" };
|
|
551
566
|
const b = c.joined.billingCodes.get(id);
|
|
552
567
|
return b === void 0 ? "unresolvedBillingCodes" : { id, name: String(_nullishCoalesce(b["name"], () => ( ""))) };
|
|
553
568
|
}
|
|
554
569
|
}
|
|
555
570
|
};
|
|
556
|
-
var fk = (rows, field) => [...rows].map((r) =>
|
|
571
|
+
var fk = (rows, field) => [...rows].map((r) => _chunk45PLS73Kcjs.num.call(void 0, r[field]));
|
|
557
572
|
var ONE_CHUNK = (idChunks) => Math.min(1, idChunks);
|
|
558
573
|
var JOINS = {
|
|
559
574
|
contracts: {
|
|
560
|
-
make: (http) => new (0,
|
|
575
|
+
make: (http) => new (0, _chunk45PLS73Kcjs.ContractsResource)(http, PAGE),
|
|
561
576
|
fields: ["id", "contractType", "contractCategory"],
|
|
562
577
|
ids: (lines) => fk(lines, "contractID")
|
|
563
578
|
},
|
|
564
579
|
companies: {
|
|
565
|
-
make: (http) => new (0,
|
|
580
|
+
make: (http) => new (0, _chunk45PLS73Kcjs.CompaniesResource)(http, PAGE),
|
|
566
581
|
fields: ["id"],
|
|
567
582
|
ids: (lines) => fk(lines, "companyID")
|
|
568
583
|
},
|
|
569
584
|
organizationalLevelAssociations: {
|
|
570
|
-
make: (http) => new (0,
|
|
585
|
+
make: (http) => new (0, _chunk45PLS73Kcjs.OrganizationalLevelAssociationsResource)(http, PAGE),
|
|
571
586
|
fields: ["id", "organizationalLevel1ID", "organizationalLevel2ID"],
|
|
572
587
|
ids: (lines) => fk(lines, "organizationalLevelAssociationID")
|
|
573
588
|
},
|
|
574
589
|
organizationalLevel1s: {
|
|
575
|
-
make: (http) => new (0,
|
|
590
|
+
make: (http) => new (0, _chunk45PLS73Kcjs.OrganizationalLevel1sResource)(http, PAGE),
|
|
576
591
|
fields: ["id", "name"],
|
|
577
592
|
ids: (_, j) => fk(j["organizationalLevelAssociations"].values(), "organizationalLevel1ID"),
|
|
578
593
|
chunks: ONE_CHUNK
|
|
579
594
|
},
|
|
580
595
|
organizationalLevel2s: {
|
|
581
|
-
make: (http) => new (0,
|
|
596
|
+
make: (http) => new (0, _chunk45PLS73Kcjs.OrganizationalLevel2sResource)(http, PAGE),
|
|
582
597
|
fields: ["id", "name"],
|
|
583
598
|
ids: (_, j) => fk(j["organizationalLevelAssociations"].values(), "organizationalLevel2ID"),
|
|
584
599
|
chunks: ONE_CHUNK
|
|
585
600
|
},
|
|
586
601
|
timeEntries: {
|
|
587
|
-
make: (http) => new (0,
|
|
602
|
+
make: (http) => new (0, _chunk45PLS73Kcjs.TimeEntriesResource)(http, PAGE),
|
|
588
603
|
fields: ["id", "resourceID"],
|
|
589
604
|
ids: (lines) => fk(lines.filter(isLabour), "timeEntryID"),
|
|
590
605
|
// One time entry per labour line: the line count is the upper bound (labour share unknown pre-walk).
|
|
591
606
|
chunks: (_, lines) => pages(lines)
|
|
592
607
|
},
|
|
593
608
|
resources: {
|
|
594
|
-
make: (http, client) => new (0,
|
|
609
|
+
make: (http, client) => new (0, _chunk45PLS73Kcjs.ResourcesResource)(http, client.config, PAGE),
|
|
595
610
|
fields: ["id", "firstName", "lastName"],
|
|
596
611
|
ids: (_, j) => fk(j["timeEntries"].values(), "resourceID"),
|
|
597
612
|
chunks: ONE_CHUNK
|
|
598
613
|
},
|
|
599
614
|
billingCodes: {
|
|
600
|
-
make: (http) => new (0,
|
|
615
|
+
make: (http) => new (0, _chunk45PLS73Kcjs.BillingCodesResource)(http, PAGE),
|
|
601
616
|
fields: ["id", "name"],
|
|
602
617
|
ids: (lines) => fk(lines, "billingCodeID")
|
|
603
618
|
}
|
|
@@ -632,7 +647,7 @@ function checkInt(name, v, def, max, problems) {
|
|
|
632
647
|
}
|
|
633
648
|
function validate(opts) {
|
|
634
649
|
if (typeof opts !== "object" || opts === null || Array.isArray(opts)) {
|
|
635
|
-
throw new (0,
|
|
650
|
+
throw new (0, _chunk45PLS73Kcjs.AutotaskConfigError)("revenueRollup: opts must be the options object { <scope>, dateFrom, dateTo, ... } (zero wire was issued)", { operation: OP });
|
|
636
651
|
}
|
|
637
652
|
const o = opts;
|
|
638
653
|
const problems = [];
|
|
@@ -649,12 +664,12 @@ function validate(opts) {
|
|
|
649
664
|
if (scopeKind === "tenantWide" && o.tenantWide !== true) problems.push("tenantWide must be exactly true");
|
|
650
665
|
}
|
|
651
666
|
const { dateFrom, dateTo } = o;
|
|
652
|
-
if (!
|
|
667
|
+
if (!_chunk45PLS73Kcjs.isDateYMD.call(void 0, dateFrom) || !_chunk45PLS73Kcjs.isDateYMD.call(void 0, dateTo)) {
|
|
653
668
|
problems.push("dateFrom and dateTo are both required as YYYY-MM-DD (the window is inclusive, whole UTC days)");
|
|
654
669
|
} else if (dateFrom > dateTo) {
|
|
655
670
|
problems.push(`dateFrom ${dateFrom} is after dateTo ${dateTo}`);
|
|
656
|
-
} else if (
|
|
657
|
-
problems.push(`the window spans ${
|
|
671
|
+
} else if (_chunk45PLS73Kcjs.monthsInWindow.call(void 0, dateFrom, dateTo) > _chunk45PLS73Kcjs.PROFITABILITY_MAX_WINDOW_MONTHS) {
|
|
672
|
+
problems.push(`the window spans ${_chunk45PLS73Kcjs.monthsInWindow.call(void 0, dateFrom, dateTo)} months; the cap is ${_chunk45PLS73Kcjs.PROFITABILITY_MAX_WINDOW_MONTHS}`);
|
|
658
673
|
}
|
|
659
674
|
let groupBy = [...DEFAULT_GROUP_BY];
|
|
660
675
|
if (o.groupBy !== void 0) {
|
|
@@ -681,7 +696,7 @@ function validate(opts) {
|
|
|
681
696
|
};
|
|
682
697
|
if (o.includeNonChargeable !== void 0 && typeof o.includeNonChargeable !== "boolean") problems.push("includeNonChargeable must be a boolean");
|
|
683
698
|
if (problems.length > 0) {
|
|
684
|
-
throw new (0,
|
|
699
|
+
throw new (0, _chunk45PLS73Kcjs.AutotaskConfigError)(`revenueRollup: ${problems.length} problem(s) found pre-request (zero wire was issued)
|
|
685
700
|
- ${problems.join("\n- ")}`, { operation: OP });
|
|
686
701
|
}
|
|
687
702
|
return v;
|
|
@@ -699,7 +714,7 @@ function resolveSelector(name, sel, values) {
|
|
|
699
714
|
}
|
|
700
715
|
function unmatched(name, what, values) {
|
|
701
716
|
const live = [...values].map(([id, l]) => `${id} ${l}`).join("; ") || "(the picklist serves no values)";
|
|
702
|
-
return new (0,
|
|
717
|
+
return new (0, _chunk45PLS73Kcjs.AutotaskConfigError)(`revenueRollup: ${name}: ${what}. Live values (id label): ${live}`, {
|
|
703
718
|
operation: OP,
|
|
704
719
|
suggestedAction: `Pass ${name} as ids or exact labels from the live list.`
|
|
705
720
|
});
|
|
@@ -710,21 +725,21 @@ var chunk = (a) => {
|
|
|
710
725
|
for (let i = 0; i < a.length; i += PAGE) out.push(a.slice(i, i + PAGE));
|
|
711
726
|
return out;
|
|
712
727
|
};
|
|
713
|
-
var byId = (rows) => [...new Map(rows.map((r) => [
|
|
714
|
-
var cents = (v) => Math.round(
|
|
715
|
-
var revC = (line) => cents(
|
|
716
|
-
var extC = (line) => cents(
|
|
728
|
+
var byId = (rows) => [...new Map(rows.map((r) => [_chunk45PLS73Kcjs.num.call(void 0, r["id"]), r])).values()];
|
|
729
|
+
var cents = (v) => Math.round(_chunk45PLS73Kcjs.num.call(void 0, v) * 100);
|
|
730
|
+
var revC = (line) => cents(_chunk45PLS73Kcjs.internalAmount.call(void 0, line, "internalCurrencyTotalAmount", "totalAmount"));
|
|
731
|
+
var extC = (line) => cents(_chunk45PLS73Kcjs.internalAmount.call(void 0, line, "internalCurrencyExtendedPrice", "extendedPrice"));
|
|
717
732
|
var INTERNAL_FIELDS = ["internalCurrencyTotalAmount", "internalCurrencyExtendedPrice"];
|
|
718
733
|
var lacksInternal = (line) => INTERNAL_FIELDS.some((k) => !Number.isFinite(line[k]));
|
|
719
734
|
var money = (c) => c / 100;
|
|
720
735
|
var pages = (n) => Math.ceil(n / PAGE);
|
|
721
736
|
async function collect(res, filter, includeFields) {
|
|
722
737
|
const out = [];
|
|
723
|
-
for await (const r of res.query({ filter, includeFields, maxRecords: PAGE })) out.push(r);
|
|
738
|
+
for await (const r of res.query({ filter, includeFields, maxRecords: PAGE, names: false })) out.push(r);
|
|
724
739
|
return out;
|
|
725
740
|
}
|
|
726
741
|
function blindCount() {
|
|
727
|
-
return new (0,
|
|
742
|
+
return new (0, _chunk45PLS73Kcjs.AutotaskError)("revenueRollup: a gate count came back blind (unknown, not zero); the roll-up cannot be sized", {
|
|
728
743
|
code: "INVALID_RESPONSE",
|
|
729
744
|
category: "server",
|
|
730
745
|
operation: OP,
|
|
@@ -734,7 +749,7 @@ function blindCount() {
|
|
|
734
749
|
}
|
|
735
750
|
function countMismatch(what, streamed, counted, rows) {
|
|
736
751
|
const rowNote = rows !== void 0 && rows !== streamed ? ` (${rows} rows)` : "";
|
|
737
|
-
return new (0,
|
|
752
|
+
return new (0, _chunk45PLS73Kcjs.AutotaskError)(`revenueRollup: 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`, {
|
|
738
753
|
code: "INVALID_RESPONSE",
|
|
739
754
|
category: "server",
|
|
740
755
|
operation: OP,
|
|
@@ -743,7 +758,7 @@ function countMismatch(what, streamed, counted, rows) {
|
|
|
743
758
|
});
|
|
744
759
|
}
|
|
745
760
|
function budgetError(message, details, suggestedAction) {
|
|
746
|
-
return new (0,
|
|
761
|
+
return new (0, _chunk45PLS73Kcjs.AutotaskError)(message, { code: "BUDGET_EXCEEDED", category: "policy", operation: OP, details, suggestedAction });
|
|
747
762
|
}
|
|
748
763
|
function lastMonthsFrom(dateTo, months) {
|
|
749
764
|
return new Date(Date.UTC(Number(dateTo.slice(0, 4)), Number(dateTo.slice(5, 7)) - months, 1)).toISOString().slice(0, 10);
|
|
@@ -776,7 +791,7 @@ async function revenueRollup(client, opts) {
|
|
|
776
791
|
const groupDims = v.groupBy.map((d) => DIMENSIONS[d]);
|
|
777
792
|
const paths = [.../* @__PURE__ */ new Set([CONTRACTS_PATH, ...groupDims.flatMap((d) => d.picklist ? [d.picklist] : [])])];
|
|
778
793
|
const labels = {};
|
|
779
|
-
for (const p of paths) labels[p] = await
|
|
794
|
+
for (const p of paths) labels[p] = await _chunk45PLS73Kcjs.readPicklists.call(void 0, http, p, OP);
|
|
780
795
|
const contractLabels = labels[CONTRACTS_PATH];
|
|
781
796
|
const typeValues = _nullishCoalesce(contractLabels.get("contractType"), () => ( /* @__PURE__ */ new Map()));
|
|
782
797
|
const inTypes = v.contractTypes ? resolveSelector("contractTypes", v.contractTypes, typeValues) : new Map([...typeValues].filter(([, l]) => DEFAULT_CONTRACT_TYPE_RE.test(l)));
|
|
@@ -785,23 +800,23 @@ async function revenueRollup(client, opts) {
|
|
|
785
800
|
let scopeIds = v.scopeIds;
|
|
786
801
|
if (v.scopeKind === "ownerResourceID") {
|
|
787
802
|
const owned = /* @__PURE__ */ new Set();
|
|
788
|
-
for await (const c of new (0,
|
|
789
|
-
const id =
|
|
803
|
+
for await (const c of new (0, _chunk45PLS73Kcjs.CompaniesResource)(http, PAGE).query({ filter: [{ field: "ownerResourceID", op: "eq", value: v.ownerResourceID }], includeFields: ["id"], maxRecords: PAGE, names: false })) {
|
|
804
|
+
const id = _chunk45PLS73Kcjs.num.call(void 0, c.id);
|
|
790
805
|
if (id > 0) owned.add(id);
|
|
791
806
|
if (owned.size > SCOPE_IDS_MAX) break;
|
|
792
807
|
}
|
|
793
808
|
scopeIds = [...owned].sort((a, b) => a - b);
|
|
794
809
|
if (scopeIds.length === 0 || scopeIds.length > SCOPE_IDS_MAX) {
|
|
795
|
-
throw new (0,
|
|
810
|
+
throw new (0, _chunk45PLS73Kcjs.AutotaskConfigError)(
|
|
796
811
|
`revenueRollup: ownerResourceID ${v.ownerResourceID} resolves to ${scopeIds.length > SCOPE_IDS_MAX ? `more than ${SCOPE_IDS_MAX}` : 0} companies (companies.query; 1..${SCOPE_IDS_MAX} supported)`,
|
|
797
812
|
{ operation: OP, suggestedAction: "Pass companyIDs explicitly, or tenantWide: true." }
|
|
798
813
|
);
|
|
799
814
|
}
|
|
800
815
|
}
|
|
801
816
|
const scopeCond = scopeIds === void 0 ? [] : [{ field: v.scopeKind === "contractIDs" ? "contractID" : "companyID", op: "in", value: scopeIds }];
|
|
802
|
-
const invoices = new (0,
|
|
803
|
-
const billingItems = new (0,
|
|
804
|
-
const windowOn = (field) => [{ field, op: "gte", value: v.dateFrom }, { field, op: "lt", value:
|
|
817
|
+
const invoices = new (0, _chunk45PLS73Kcjs.InvoicesResource)(http, PAGE);
|
|
818
|
+
const billingItems = new (0, _chunk45PLS73Kcjs.BillingItemsResource)(http, PAGE);
|
|
819
|
+
const windowOn = (field) => [{ field, op: "gte", value: v.dateFrom }, { field, op: "lt", value: _chunk45PLS73Kcjs.dayAfter.call(void 0, v.dateTo) }];
|
|
805
820
|
const invoiceFilter = (voided2) => [...windowOn("invoiceDateTime"), { field: "isVoided", op: "eq", value: voided2 }];
|
|
806
821
|
const withVoided = v.scopeKind !== "contractIDs";
|
|
807
822
|
const voidedFilter = [...invoiceFilter(true), ...scopeIds !== void 0 && withVoided ? [{ field: "companyID", op: "in", value: scopeIds }] : []];
|
|
@@ -810,7 +825,7 @@ async function revenueRollup(client, opts) {
|
|
|
810
825
|
const uninvoicedFilter = [{ field: "invoiceID", op: "notExist" }, ...windowOn("itemDate"), ...scopeCond];
|
|
811
826
|
const nUninvoiced = v.nonChargeable ? await billingItems.count({ filter: uninvoicedFilter }) : 0;
|
|
812
827
|
if (typeof nInvoices !== "number" || typeof nLines !== "number" || typeof nUninvoiced !== "number") throw blindCount();
|
|
813
|
-
const joinsNeeded = Object.keys(JOINS).filter((j) => j === "contracts" || groupDims.some((d) => _optionalChain([d, 'access',
|
|
828
|
+
const joinsNeeded = Object.keys(JOINS).filter((j) => j === "contracts" || groupDims.some((d) => _optionalChain([d, 'access', _23 => _23.joins, 'optionalAccess', _24 => _24[j]])));
|
|
814
829
|
const chunks = pages(nInvoices);
|
|
815
830
|
const linePages = chunks + Math.max(0, pages(nLines) - 1) + chunks;
|
|
816
831
|
const uninvoicedPages = v.nonChargeable ? Math.max(1, pages(nUninvoiced)) : 0;
|
|
@@ -825,7 +840,7 @@ async function revenueRollup(client, opts) {
|
|
|
825
840
|
const invoiceRows = await collect(invoices, invoiceFilter(false), ["id", "invoiceTotal", "invoiceDateTime", "companyID"]);
|
|
826
841
|
const invoiceById = /* @__PURE__ */ new Map();
|
|
827
842
|
for (const r of invoiceRows) {
|
|
828
|
-
invoiceById.set(
|
|
843
|
+
invoiceById.set(_chunk45PLS73Kcjs.num.call(void 0, r["id"]), { total: cents(r["invoiceTotal"]), month: String(_nullishCoalesce(r["invoiceDateTime"], () => ( ""))).slice(0, 7), companyID: _chunk45PLS73Kcjs.num.call(void 0, r["companyID"]) });
|
|
829
844
|
}
|
|
830
845
|
if (invoiceById.size !== nInvoices) throw countMismatch("invoice", invoiceById.size, nInvoices, invoiceRows.length);
|
|
831
846
|
const voided = withVoided ? byId(await collect(invoices, voidedFilter, ["id", "invoiceTotal"])) : void 0;
|
|
@@ -839,13 +854,13 @@ async function revenueRollup(client, opts) {
|
|
|
839
854
|
if (rows.length !== n) throw countMismatch("line", rows.length, n);
|
|
840
855
|
return rows;
|
|
841
856
|
}, chunk(ids), { concurrency: CONCURRENCY })).flat();
|
|
842
|
-
const orphan = lines.find((l) => !invoiceById.has(
|
|
857
|
+
const orphan = lines.find((l) => !invoiceById.has(_chunk45PLS73Kcjs.num.call(void 0, l["invoiceID"])));
|
|
843
858
|
if (orphan !== void 0) {
|
|
844
|
-
throw new (0,
|
|
859
|
+
throw new (0, _chunk45PLS73Kcjs.AutotaskError)(`revenueRollup: billing line ${_chunk45PLS73Kcjs.num.call(void 0, orphan["id"])} belongs to invoice ${_chunk45PLS73Kcjs.num.call(void 0, orphan["invoiceID"])}, which is not among the ${invoiceById.size} streamed invoices; the fold was discarded`, {
|
|
845
860
|
code: "INVALID_RESPONSE",
|
|
846
861
|
category: "server",
|
|
847
862
|
operation: OP,
|
|
848
|
-
details: { reason: "orphan_line", lineID:
|
|
863
|
+
details: { reason: "orphan_line", lineID: _chunk45PLS73Kcjs.num.call(void 0, orphan["id"]), invoiceID: _chunk45PLS73Kcjs.num.call(void 0, orphan["invoiceID"]) },
|
|
849
864
|
suggestedAction: "Retry the call."
|
|
850
865
|
});
|
|
851
866
|
}
|
|
@@ -856,15 +871,15 @@ async function revenueRollup(client, opts) {
|
|
|
856
871
|
for (const j of joinsNeeded) {
|
|
857
872
|
const spec = JOINS[j];
|
|
858
873
|
const res = spec.make(http, client);
|
|
859
|
-
const fields = [.../* @__PURE__ */ new Set([...spec.fields, ...groupDims.flatMap((d) => _nullishCoalesce(_optionalChain([d, 'access',
|
|
874
|
+
const fields = [.../* @__PURE__ */ new Set([...spec.fields, ...groupDims.flatMap((d) => _nullishCoalesce(_optionalChain([d, 'access', _25 => _25.joins, 'optionalAccess', _26 => _26[j]]), () => ( [])))])];
|
|
860
875
|
const want = [...new Set(spec.ids(all, joined))].filter((id) => id > 0).sort((a, b) => a - b);
|
|
861
876
|
const rows = await client.batch((c) => collect(res, [{ field: "id", op: "in", value: c }], fields), chunk(want), { concurrency: CONCURRENCY });
|
|
862
|
-
for (const r of rows.flat()) joined[j].set(
|
|
877
|
+
for (const r of rows.flat()) joined[j].set(_chunk45PLS73Kcjs.num.call(void 0, r["id"]), r);
|
|
863
878
|
}
|
|
864
879
|
return fold(v, { invoiceById, voided, lines, uninvoiced, joined, labels, inTypes, inCategories, scopeIds, calls, estimate });
|
|
865
880
|
}
|
|
866
881
|
function refusal(v, estimate, fixed, scopeIds, joinCount) {
|
|
867
|
-
const months =
|
|
882
|
+
const months = _chunk45PLS73Kcjs.monthsInWindow.call(void 0, v.dateFrom, v.dateTo);
|
|
868
883
|
const variable = estimate - fixed;
|
|
869
884
|
const fitMonths = Math.floor((v.budget - fixed) * months / variable);
|
|
870
885
|
const suggestions = [];
|
|
@@ -937,13 +952,13 @@ function fold(v, f) {
|
|
|
937
952
|
const contractLabels = f.labels[CONTRACTS_PATH];
|
|
938
953
|
const bucketLabel = (field, fallback) => (t) => {
|
|
939
954
|
const values = contractLabels.get(field);
|
|
940
|
-
const l = _optionalChain([values, 'optionalAccess',
|
|
955
|
+
const l = _optionalChain([values, 'optionalAccess', _27 => _27.get, 'call', _28 => _28(t)]);
|
|
941
956
|
if (l === void 0) return `${fallback} ${t}`;
|
|
942
957
|
return [...values.values()].filter((x) => x === l).length > 1 ? `${l} (${t})` : l;
|
|
943
958
|
};
|
|
944
959
|
const typeLabel = bucketLabel("contractType", "type");
|
|
945
960
|
const catLabel = bucketLabel("contractCategory", "category");
|
|
946
|
-
const needCompany = v.groupBy.some((d) => _optionalChain([DIMENSIONS, 'access',
|
|
961
|
+
const needCompany = v.groupBy.some((d) => _optionalChain([DIMENSIONS, 'access', _29 => _29[d], 'access', _30 => _30.joins, 'optionalAccess', _31 => _31.companies]));
|
|
947
962
|
const byLob = v.groupBy.includes("lineOfBusiness");
|
|
948
963
|
const unlabelled = /* @__PURE__ */ new Set();
|
|
949
964
|
const uncontracted = amt();
|
|
@@ -960,15 +975,15 @@ function fold(v, f) {
|
|
|
960
975
|
const zeroTotal = amt();
|
|
961
976
|
const zeroIds = /* @__PURE__ */ new Set();
|
|
962
977
|
const locate = (line, invoice) => {
|
|
963
|
-
const contractID =
|
|
978
|
+
const contractID = _chunk45PLS73Kcjs.num.call(void 0, line["contractID"]);
|
|
964
979
|
if (contractID === 0) return { bucket: uncontracted, unresolved: false };
|
|
965
980
|
const contract = f.joined.contracts.get(contractID);
|
|
966
981
|
if (contract === void 0) return { bucket: unresolvedContracts, unresolved: true };
|
|
967
|
-
const type =
|
|
982
|
+
const type = _chunk45PLS73Kcjs.num.call(void 0, contract["contractType"]);
|
|
968
983
|
if (!f.inTypes.has(type)) return { bucket: slot(otherTypes, typeLabel(type)), unresolved: false };
|
|
969
|
-
const cat =
|
|
984
|
+
const cat = _chunk45PLS73Kcjs.num.call(void 0, contract["contractCategory"]);
|
|
970
985
|
if (f.inCategories !== void 0 && !f.inCategories.has(cat)) return { bucket: slot(otherCats, cat === 0 ? "uncategorised" : catLabel(cat)), unresolved: false };
|
|
971
|
-
const company = f.joined.companies.get(
|
|
986
|
+
const company = f.joined.companies.get(_chunk45PLS73Kcjs.num.call(void 0, line["companyID"]));
|
|
972
987
|
if (needCompany && company === void 0) return { bucket: unresolvedCompanies, unresolved: true };
|
|
973
988
|
const ctx = { line, invoice, contract, company, joined: f.joined, labels: f.labels, unlabelled };
|
|
974
989
|
const keys = {};
|
|
@@ -988,7 +1003,7 @@ function fold(v, f) {
|
|
|
988
1003
|
return { cell };
|
|
989
1004
|
};
|
|
990
1005
|
for (const line of f.lines) {
|
|
991
|
-
const invoiceID =
|
|
1006
|
+
const invoiceID = _chunk45PLS73Kcjs.num.call(void 0, line["invoiceID"]);
|
|
992
1007
|
const invoice = f.invoiceById.get(invoiceID);
|
|
993
1008
|
lineTotals.set(invoiceID, (_nullishCoalesce(lineTotals.get(invoiceID), () => ( 0))) + cents(line["totalAmount"]));
|
|
994
1009
|
const c = revC(line);
|
|
@@ -1009,9 +1024,9 @@ function fold(v, f) {
|
|
|
1009
1024
|
cell.creditLines += 1;
|
|
1010
1025
|
}
|
|
1011
1026
|
cell.included += extC(line) - c;
|
|
1012
|
-
cell.contracts.add(
|
|
1027
|
+
cell.contracts.add(_chunk45PLS73Kcjs.num.call(void 0, line["contractID"]));
|
|
1013
1028
|
cell.items += 1;
|
|
1014
|
-
allContracts.add(
|
|
1029
|
+
allContracts.add(_chunk45PLS73Kcjs.num.call(void 0, line["contractID"]));
|
|
1015
1030
|
if (byLob && cell.keys.lineOfBusiness.id === null) add(noPointer, c);
|
|
1016
1031
|
const k = v.nonChargeable ? ncClass(line) : void 0;
|
|
1017
1032
|
if (k) ncAdd(cell.nc, k, line);
|
|
@@ -1019,7 +1034,7 @@ function fold(v, f) {
|
|
|
1019
1034
|
for (const line of f.uninvoiced) {
|
|
1020
1035
|
const k = ncClass(line);
|
|
1021
1036
|
if (!k) continue;
|
|
1022
|
-
const at = locate(line, { total: 0, month: String(_nullishCoalesce(line["itemDate"], () => ( ""))).slice(0, 7), companyID:
|
|
1037
|
+
const at = locate(line, { total: 0, month: String(_nullishCoalesce(line["itemDate"], () => ( ""))).slice(0, 7), companyID: _chunk45PLS73Kcjs.num.call(void 0, line["companyID"]) });
|
|
1023
1038
|
if ("cell" in at) ncAdd(at.cell.nc, k, line);
|
|
1024
1039
|
else if (at.unresolved) add(unresolvedNc, extC(line));
|
|
1025
1040
|
}
|
|
@@ -1129,20 +1144,20 @@ function slot(m, k) {
|
|
|
1129
1144
|
async function relationshipMap(client, resourceKey) {
|
|
1130
1145
|
void client;
|
|
1131
1146
|
if (typeof resourceKey !== "string" || resourceKey.trim() === "") {
|
|
1132
|
-
throw new (0,
|
|
1147
|
+
throw new (0, _chunk45PLS73Kcjs.AutotaskConfigError)(
|
|
1133
1148
|
`relationshipMap: resourceKey must be a non-empty plan resource key string (e.g. 'tickets'; got ${typeof resourceKey === "string" ? "a blank string" : typeof resourceKey})`,
|
|
1134
1149
|
{ suggestedAction: "Pass the exact plan resource key (snake_case) from autotask_catalog \u2014 e.g. tickets, companies, configuration_items, ticket_notes." }
|
|
1135
1150
|
);
|
|
1136
1151
|
}
|
|
1137
1152
|
const key = resourceKey.trim();
|
|
1138
|
-
const entry =
|
|
1153
|
+
const entry = _chunk45PLS73Kcjs.RELATIONSHIP_MAP[key];
|
|
1139
1154
|
if (entry === void 0) {
|
|
1140
|
-
throw new (0,
|
|
1141
|
-
`relationshipMap: unknown resource "${key}" \u2014 the plan has ${Object.keys(
|
|
1155
|
+
throw new (0, _chunk45PLS73Kcjs.AutotaskError)(
|
|
1156
|
+
`relationshipMap: unknown resource "${key}" \u2014 the plan has ${Object.keys(_chunk45PLS73Kcjs.RELATIONSHIP_MAP).length} resources`,
|
|
1142
1157
|
{
|
|
1143
1158
|
code: "RESOURCE_UNKNOWN",
|
|
1144
1159
|
category: "validation",
|
|
1145
|
-
suggestedAction: `Pass the exact plan resource key (snake_case) from autotask_catalog (e.g. tickets, companies, configuration_items). Zone facts served are ${
|
|
1160
|
+
suggestedAction: `Pass the exact plan resource key (snake_case) from autotask_catalog (e.g. tickets, companies, configuration_items). Zone facts served are ${_chunk45PLS73Kcjs.RELATIONSHIP_ZONE.label} (${_chunk45PLS73Kcjs.RELATIONSHIP_ZONE.zone})-verified.`
|
|
1146
1161
|
}
|
|
1147
1162
|
);
|
|
1148
1163
|
}
|
|
@@ -1159,24 +1174,24 @@ var BLIND_SURFACE_KINDS = [
|
|
|
1159
1174
|
async function blindSurfaces(client, opts) {
|
|
1160
1175
|
void client;
|
|
1161
1176
|
if (opts !== void 0 && (typeof opts !== "object" || opts === null || Array.isArray(opts))) {
|
|
1162
|
-
throw new (0,
|
|
1177
|
+
throw new (0, _chunk45PLS73Kcjs.AutotaskConfigError)("blindSurfaces: opts must be an object { resource?: string, kind?: BlindSurfaceKind }");
|
|
1163
1178
|
}
|
|
1164
|
-
const inv =
|
|
1179
|
+
const inv = _chunk45PLS73Kcjs.BLIND_SURFACE_INVENTORY;
|
|
1165
1180
|
if (inv === null) {
|
|
1166
|
-
throw new (0,
|
|
1181
|
+
throw new (0, _chunk45PLS73Kcjs.AutotaskConfigError)("blindSurfaces: the reachability inventory is absent from the generated artifact \u2014 re-run the build");
|
|
1167
1182
|
}
|
|
1168
1183
|
let surfaces = inv.surfaces;
|
|
1169
|
-
if (_optionalChain([opts, 'optionalAccess',
|
|
1184
|
+
if (_optionalChain([opts, 'optionalAccess', _32 => _32.resource]) !== void 0) {
|
|
1170
1185
|
const key = typeof opts.resource === "string" ? opts.resource.trim() : "";
|
|
1171
1186
|
if (key === "") {
|
|
1172
|
-
throw new (0,
|
|
1187
|
+
throw new (0, _chunk45PLS73Kcjs.AutotaskConfigError)(
|
|
1173
1188
|
"blindSurfaces: opts.resource must be a non-empty plan resource key string (e.g. 'tickets')",
|
|
1174
1189
|
{ suggestedAction: "Pass the exact plan resource key (snake_case) from autotask_catalog \u2014 e.g. tickets, companies, configuration_items." }
|
|
1175
1190
|
);
|
|
1176
1191
|
}
|
|
1177
1192
|
if (!inv.surfaces.some((row) => row.resource === key)) {
|
|
1178
|
-
throw new (0,
|
|
1179
|
-
`blindSurfaces: unknown resource "${key}" \u2014 the plan has ${Object.keys(
|
|
1193
|
+
throw new (0, _chunk45PLS73Kcjs.AutotaskError)(
|
|
1194
|
+
`blindSurfaces: unknown resource "${key}" \u2014 the plan has ${Object.keys(_chunk45PLS73Kcjs.RELATIONSHIP_MAP).length} resources`,
|
|
1180
1195
|
{
|
|
1181
1196
|
code: "RESOURCE_UNKNOWN",
|
|
1182
1197
|
category: "validation",
|
|
@@ -1186,9 +1201,9 @@ async function blindSurfaces(client, opts) {
|
|
|
1186
1201
|
}
|
|
1187
1202
|
surfaces = surfaces.filter((row) => row.resource === key);
|
|
1188
1203
|
}
|
|
1189
|
-
if (_optionalChain([opts, 'optionalAccess',
|
|
1204
|
+
if (_optionalChain([opts, 'optionalAccess', _33 => _33.kind]) !== void 0) {
|
|
1190
1205
|
if (!BLIND_SURFACE_KINDS.includes(opts.kind)) {
|
|
1191
|
-
throw new (0,
|
|
1206
|
+
throw new (0, _chunk45PLS73Kcjs.AutotaskConfigError)(
|
|
1192
1207
|
`blindSurfaces: unknown kind "${String(opts.kind)}" \u2014 the valid classes are: ${BLIND_SURFACE_KINDS.join(", ")}`,
|
|
1193
1208
|
{ suggestedAction: `Filter with one of: ${BLIND_SURFACE_KINDS.join(", ")} (or omit kind for the full 116-surface inventory).` }
|
|
1194
1209
|
);
|
|
@@ -1201,51 +1216,51 @@ async function blindSurfaces(client, opts) {
|
|
|
1201
1216
|
// src/operations/probeReachability.ts
|
|
1202
1217
|
async function probeReachability(client, opts) {
|
|
1203
1218
|
if (opts !== void 0 && (typeof opts !== "object" || opts === null || Array.isArray(opts))) {
|
|
1204
|
-
throw new (0,
|
|
1219
|
+
throw new (0, _chunk45PLS73Kcjs.AutotaskConfigError)("probeReachability: opts must be an object { resources?: string[], limit?: 1|2, maxWireCalls?: number, confirmProbe?: true }");
|
|
1205
1220
|
}
|
|
1206
|
-
const defs =
|
|
1207
|
-
if (_optionalChain([opts, 'optionalAccess',
|
|
1208
|
-
throw new (0,
|
|
1221
|
+
const defs = _chunk45PLS73Kcjs.REACHABILITY_PROBE_DEFAULTS;
|
|
1222
|
+
if (_optionalChain([opts, 'optionalAccess', _34 => _34.confirmProbe]) !== true) {
|
|
1223
|
+
throw new (0, _chunk45PLS73Kcjs.AutotaskConfigError)(
|
|
1209
1224
|
"probeReachability: confirmProbe: true is required \u2014 the op deliberately fans out read wire across the tenant (one bounded query per surface); pass confirmProbe: true to run it",
|
|
1210
1225
|
{ suggestedAction: `Re-call with { confirmProbe: true } (plus resources/limit/maxWireCalls as needed). For the ZERO-wire pinned inventory use operations.blindSurfaces.` }
|
|
1211
1226
|
);
|
|
1212
1227
|
}
|
|
1213
|
-
const limit = _nullishCoalesce(_optionalChain([opts, 'optionalAccess',
|
|
1228
|
+
const limit = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _35 => _35.limit]), () => ( defs.limitDefault));
|
|
1214
1229
|
if (!Number.isInteger(limit) || limit < 1 || limit > defs.limitMax) {
|
|
1215
|
-
throw new (0,
|
|
1230
|
+
throw new (0, _chunk45PLS73Kcjs.AutotaskConfigError)(
|
|
1216
1231
|
`probeReachability: limit must be an integer 1..${defs.limitMax} (got ${String(limit)}) \u2014 the rows-per-surface bound for the discovery read`
|
|
1217
1232
|
);
|
|
1218
1233
|
}
|
|
1219
|
-
const cap = _nullishCoalesce(_optionalChain([opts, 'optionalAccess',
|
|
1234
|
+
const cap = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _36 => _36.maxWireCalls]), () => ( defs.defaultCap));
|
|
1220
1235
|
if (!Number.isInteger(cap) || cap < 1) {
|
|
1221
|
-
throw new (0,
|
|
1236
|
+
throw new (0, _chunk45PLS73Kcjs.AutotaskConfigError)(`probeReachability: maxWireCalls must be a positive integer (got ${String(cap)})`);
|
|
1222
1237
|
}
|
|
1223
1238
|
if (cap > defs.hardCap) {
|
|
1224
|
-
throw new (0,
|
|
1239
|
+
throw new (0, _chunk45PLS73Kcjs.AutotaskConfigError)(
|
|
1225
1240
|
`probeReachability: maxWireCalls ${cap} exceeds the hard wire cap of ${defs.hardCap} \u2014 the sweep is refused above it (never capped silently)`,
|
|
1226
1241
|
{ suggestedAction: `Pass maxWireCalls \u2264 ${defs.hardCap} and a resources set no larger than the cap (the refused set is never truncated).` }
|
|
1227
1242
|
);
|
|
1228
1243
|
}
|
|
1229
|
-
const inv =
|
|
1244
|
+
const inv = _chunk45PLS73Kcjs.BLIND_SURFACE_INVENTORY;
|
|
1230
1245
|
if (inv === null) {
|
|
1231
|
-
throw new (0,
|
|
1246
|
+
throw new (0, _chunk45PLS73Kcjs.AutotaskConfigError)("probeReachability: the reachability inventory is absent from the generated artifact \u2014 re-run the build");
|
|
1232
1247
|
}
|
|
1233
1248
|
let targets;
|
|
1234
|
-
if (_optionalChain([opts, 'optionalAccess',
|
|
1249
|
+
if (_optionalChain([opts, 'optionalAccess', _37 => _37.resources]) === void 0) {
|
|
1235
1250
|
targets = [...defs.defaultTargets];
|
|
1236
1251
|
} else {
|
|
1237
1252
|
if (!Array.isArray(opts.resources) || opts.resources.length === 0) {
|
|
1238
|
-
throw new (0,
|
|
1253
|
+
throw new (0, _chunk45PLS73Kcjs.AutotaskConfigError)("probeReachability: opts.resources must be a non-empty string[] of plan resource keys (or omit it for the default non-data-full set)");
|
|
1239
1254
|
}
|
|
1240
1255
|
const seen = /* @__PURE__ */ new Set();
|
|
1241
1256
|
for (const r of opts.resources) {
|
|
1242
1257
|
if (typeof r !== "string" || r.trim() === "") {
|
|
1243
|
-
throw new (0,
|
|
1258
|
+
throw new (0, _chunk45PLS73Kcjs.AutotaskConfigError)(`probeReachability: opts.resources must contain non-empty plan resource key strings (got ${typeof r === "string" && r.trim() === "" ? "a blank string" : typeof r})`);
|
|
1244
1259
|
}
|
|
1245
1260
|
const key = r.trim();
|
|
1246
1261
|
if (!inv.surfaces.some((row) => row.resource === key)) {
|
|
1247
1262
|
const surfaceCount = new Set(inv.surfaces.map((s) => s.resource)).size;
|
|
1248
|
-
throw new (0,
|
|
1263
|
+
throw new (0, _chunk45PLS73Kcjs.AutotaskError)(
|
|
1249
1264
|
`probeReachability: unknown resource "${key}" \u2014 the inventory has ${surfaceCount} surfaces`,
|
|
1250
1265
|
{
|
|
1251
1266
|
code: "RESOURCE_UNKNOWN",
|
|
@@ -1259,7 +1274,7 @@ async function probeReachability(client, opts) {
|
|
|
1259
1274
|
targets = [...seen];
|
|
1260
1275
|
}
|
|
1261
1276
|
if (targets.length > cap) {
|
|
1262
|
-
throw new (0,
|
|
1277
|
+
throw new (0, _chunk45PLS73Kcjs.AutotaskConfigError)(
|
|
1263
1278
|
`probeReachability: ${targets.length} requested surface(s) exceed the wire cap of ${cap} \u2014 the sweep is refused above its cap (never truncated)`,
|
|
1264
1279
|
{ suggestedAction: `Raise maxWireCalls (\u2264 ${defs.hardCap}) to cover the set, or pass a smaller resources list.` }
|
|
1265
1280
|
);
|
|
@@ -1269,8 +1284,8 @@ async function probeReachability(client, opts) {
|
|
|
1269
1284
|
for (const resource of targets.sort()) {
|
|
1270
1285
|
const row = byResource.get(resource);
|
|
1271
1286
|
if (row === void 0) continue;
|
|
1272
|
-
const holder = client[
|
|
1273
|
-
const probeFn = _optionalChain([holder, 'optionalAccess',
|
|
1287
|
+
const holder = client[_chunk45PLS73Kcjs.camelKey.call(void 0, resource)];
|
|
1288
|
+
const probeFn = _optionalChain([holder, 'optionalAccess', _38 => _38.queryBounded]);
|
|
1274
1289
|
if (typeof probeFn !== "function") {
|
|
1275
1290
|
results.push({
|
|
1276
1291
|
...row,
|
|
@@ -1281,14 +1296,14 @@ async function probeReachability(client, opts) {
|
|
|
1281
1296
|
}
|
|
1282
1297
|
try {
|
|
1283
1298
|
const res = await probeFn.call(holder, { limit });
|
|
1284
|
-
const items = Array.isArray(_optionalChain([res, 'optionalAccess',
|
|
1299
|
+
const items = Array.isArray(_optionalChain([res, 'optionalAccess', _39 => _39.items])) ? res.items : [];
|
|
1285
1300
|
results.push({
|
|
1286
1301
|
...row,
|
|
1287
1302
|
unfilteredRows: items.length,
|
|
1288
1303
|
probe: { ok: true, wire: 1, error: null }
|
|
1289
1304
|
});
|
|
1290
1305
|
} catch (err) {
|
|
1291
|
-
const code =
|
|
1306
|
+
const code = _chunk45PLS73Kcjs.isAutotaskError.call(void 0, err) ? err.code : "NETWORK_ERROR";
|
|
1292
1307
|
const message = err instanceof Error ? err.message : String(err);
|
|
1293
1308
|
results.push({
|
|
1294
1309
|
...row,
|
|
@@ -1316,30 +1331,30 @@ var CREATE_BLOCKER_KINDS = [
|
|
|
1316
1331
|
async function createGuidance(client, opts) {
|
|
1317
1332
|
void client;
|
|
1318
1333
|
if (opts !== void 0 && (typeof opts !== "object" || opts === null || Array.isArray(opts))) {
|
|
1319
|
-
throw new (0,
|
|
1334
|
+
throw new (0, _chunk45PLS73Kcjs.AutotaskConfigError)(
|
|
1320
1335
|
"createGuidance: opts must be an object { resources?: string[], kind?: CreateBlockerKind }"
|
|
1321
1336
|
);
|
|
1322
1337
|
}
|
|
1323
|
-
let servedRows =
|
|
1338
|
+
let servedRows = _chunk45PLS73Kcjs.CREATE_GUIDANCE.rows.map((row) => ({
|
|
1324
1339
|
...row,
|
|
1325
1340
|
// Issue #219 N4: one precedence rule, stated on every row (live-proven >
|
|
1326
1341
|
// zone > spec). The spec set is not available here (it is a LIVE read) —
|
|
1327
1342
|
// the helper is handed the plan's two shapes and names the source.
|
|
1328
|
-
requiredFields:
|
|
1343
|
+
requiredFields: _chunk45PLS73Kcjs.effectiveRequiredFields.call(void 0, void 0, _nullishCoalesce(_optionalChain([_chunk45PLS73Kcjs.RELATIONSHIP_MAP, 'access', _40 => _40[row.resource], 'optionalAccess', _41 => _41.zoneFacts]), () => ( null)))
|
|
1329
1344
|
}));
|
|
1330
|
-
if (_optionalChain([opts, 'optionalAccess',
|
|
1345
|
+
if (_optionalChain([opts, 'optionalAccess', _42 => _42.resources]) !== void 0) {
|
|
1331
1346
|
if (!Array.isArray(opts.resources) || opts.resources.length === 0) {
|
|
1332
|
-
throw new (0,
|
|
1347
|
+
throw new (0, _chunk45PLS73Kcjs.AutotaskConfigError)("createGuidance: opts.resources must be a non-empty string[] of plan resource keys");
|
|
1333
1348
|
}
|
|
1334
1349
|
const wanted = /* @__PURE__ */ new Set();
|
|
1335
1350
|
for (const r of opts.resources) {
|
|
1336
1351
|
if (typeof r !== "string" || r.trim() === "") {
|
|
1337
|
-
throw new (0,
|
|
1352
|
+
throw new (0, _chunk45PLS73Kcjs.AutotaskConfigError)("createGuidance: opts.resources must contain non-empty plan resource key strings");
|
|
1338
1353
|
}
|
|
1339
1354
|
const key = r.trim();
|
|
1340
|
-
if (!
|
|
1341
|
-
throw new (0,
|
|
1342
|
-
`createGuidance: unknown resource "${key}" \u2014 the catalog has ${
|
|
1355
|
+
if (!_chunk45PLS73Kcjs.CREATE_GUIDANCE.rows.some((row) => row.resource === key)) {
|
|
1356
|
+
throw new (0, _chunk45PLS73Kcjs.AutotaskError)(
|
|
1357
|
+
`createGuidance: unknown resource "${key}" \u2014 the catalog has ${_chunk45PLS73Kcjs.CREATE_GUIDANCE.rows.length} create entities`,
|
|
1343
1358
|
{
|
|
1344
1359
|
code: "RESOURCE_UNKNOWN",
|
|
1345
1360
|
category: "validation",
|
|
@@ -1351,20 +1366,20 @@ async function createGuidance(client, opts) {
|
|
|
1351
1366
|
}
|
|
1352
1367
|
servedRows = servedRows.filter((row) => wanted.has(row.resource));
|
|
1353
1368
|
}
|
|
1354
|
-
if (_optionalChain([opts, 'optionalAccess',
|
|
1369
|
+
if (_optionalChain([opts, 'optionalAccess', _43 => _43.kind]) !== void 0) {
|
|
1355
1370
|
if (!CREATE_BLOCKER_KINDS.includes(opts.kind)) {
|
|
1356
|
-
throw new (0,
|
|
1371
|
+
throw new (0, _chunk45PLS73Kcjs.AutotaskConfigError)(
|
|
1357
1372
|
`createGuidance: unknown kind "${String(opts.kind)}" \u2014 the valid kinds are: ${CREATE_BLOCKER_KINDS.join(", ")}`
|
|
1358
1373
|
);
|
|
1359
1374
|
}
|
|
1360
|
-
servedRows = servedRows.filter((row) => _optionalChain([row, 'access',
|
|
1375
|
+
servedRows = servedRows.filter((row) => _optionalChain([row, 'access', _44 => _44.blocker, 'optionalAccess', _45 => _45.kind]) === opts.kind);
|
|
1361
1376
|
}
|
|
1362
1377
|
return {
|
|
1363
|
-
zone:
|
|
1364
|
-
label:
|
|
1365
|
-
verifiedAt:
|
|
1378
|
+
zone: _chunk45PLS73Kcjs.CREATE_GUIDANCE.zone,
|
|
1379
|
+
label: _chunk45PLS73Kcjs.CREATE_GUIDANCE.label,
|
|
1380
|
+
verifiedAt: _chunk45PLS73Kcjs.CREATE_GUIDANCE.verifiedAt,
|
|
1366
1381
|
rows: servedRows,
|
|
1367
|
-
counts:
|
|
1382
|
+
counts: _chunk45PLS73Kcjs.CREATE_GUIDANCE.counts
|
|
1368
1383
|
};
|
|
1369
1384
|
}
|
|
1370
1385
|
|
|
@@ -1373,7 +1388,7 @@ var RECOVERY_CONFIRM = "operations.recovery";
|
|
|
1373
1388
|
var RECOVERY_DEFAULT_LIMIT = 25;
|
|
1374
1389
|
var RECOVERY_MAX_LIMIT = 100;
|
|
1375
1390
|
function configError(message, operation, suggestedAction) {
|
|
1376
|
-
throw new (0,
|
|
1391
|
+
throw new (0, _chunk45PLS73Kcjs.AutotaskConfigError)(message, { operation, suggestedAction });
|
|
1377
1392
|
}
|
|
1378
1393
|
function parseMatchId(record) {
|
|
1379
1394
|
const raw = record.id;
|
|
@@ -1389,7 +1404,7 @@ function parseMatchId(record) {
|
|
|
1389
1404
|
return { id: null, unsafe: true };
|
|
1390
1405
|
}
|
|
1391
1406
|
function validateRecoveryInput(input, operation) {
|
|
1392
|
-
if (!
|
|
1407
|
+
if (!_chunk45PLS73Kcjs.isRecord.call(void 0, input)) {
|
|
1393
1408
|
configError(
|
|
1394
1409
|
`recovery: input must be an object { resource, marker, ... } (got ${typeof input})`,
|
|
1395
1410
|
operation,
|
|
@@ -1423,10 +1438,10 @@ function validateRecoveryInput(input, operation) {
|
|
|
1423
1438
|
return { resource, marker, action };
|
|
1424
1439
|
}
|
|
1425
1440
|
function resolveRecoveryTarget(client, resource, operation) {
|
|
1426
|
-
const entry =
|
|
1441
|
+
const entry = _chunk45PLS73Kcjs.RELATIONSHIP_MAP[resource];
|
|
1427
1442
|
if (entry === void 0) {
|
|
1428
|
-
throw new (0,
|
|
1429
|
-
`recovery: unknown resource "${resource}" \u2014 the plan has ${Object.keys(
|
|
1443
|
+
throw new (0, _chunk45PLS73Kcjs.AutotaskError)(
|
|
1444
|
+
`recovery: unknown resource "${resource}" \u2014 the plan has ${Object.keys(_chunk45PLS73Kcjs.RELATIONSHIP_MAP).length} resources`,
|
|
1430
1445
|
{
|
|
1431
1446
|
code: "RESOURCE_UNKNOWN",
|
|
1432
1447
|
category: "validation",
|
|
@@ -1435,7 +1450,7 @@ function resolveRecoveryTarget(client, resource, operation) {
|
|
|
1435
1450
|
}
|
|
1436
1451
|
);
|
|
1437
1452
|
}
|
|
1438
|
-
const holder = client[
|
|
1453
|
+
const holder = client[_chunk45PLS73Kcjs.camelKey.call(void 0, resource)];
|
|
1439
1454
|
if (!holder || typeof holder.queryBounded !== "function") {
|
|
1440
1455
|
configError(
|
|
1441
1456
|
`recovery: ${resource} exposes no bounded query surface \u2014 the marker search cannot run`,
|
|
@@ -1446,7 +1461,7 @@ function resolveRecoveryTarget(client, resource, operation) {
|
|
|
1446
1461
|
return { entry, holder };
|
|
1447
1462
|
}
|
|
1448
1463
|
function resolveMarkerField(input, resource, operation) {
|
|
1449
|
-
const field = input.field !== void 0 ? String(input.field) :
|
|
1464
|
+
const field = input.field !== void 0 ? String(input.field) : _chunk45PLS73Kcjs.MARKER_FIELDS[resource];
|
|
1450
1465
|
if (typeof field !== "string" || field.trim() === "") {
|
|
1451
1466
|
configError(
|
|
1452
1467
|
`recovery: ${resource} has no plan markerField and no input.field was passed \u2014 the marker search needs a name-like field to filter on`,
|
|
@@ -1485,7 +1500,7 @@ function resolveExtraFilter(input, operation) {
|
|
|
1485
1500
|
);
|
|
1486
1501
|
}
|
|
1487
1502
|
for (const c of input.filter) {
|
|
1488
|
-
if (!
|
|
1503
|
+
if (!_chunk45PLS73Kcjs.isRecord.call(void 0, c) || typeof c.op !== "string" || c.op === "and" || c.op === "or") {
|
|
1489
1504
|
configError(
|
|
1490
1505
|
"recovery: input.filter accepts only plain leaf conditions ({ field, op, value }) \u2014 no grouping",
|
|
1491
1506
|
operation,
|
|
@@ -1510,7 +1525,7 @@ function resolveLimit(input, operation) {
|
|
|
1510
1525
|
async function applyRecoveryDeletes(holder, matches, parentId, resource, operation) {
|
|
1511
1526
|
const deleteMethod = holder.delete;
|
|
1512
1527
|
if (deleteMethod === void 0) {
|
|
1513
|
-
throw new (0,
|
|
1528
|
+
throw new (0, _chunk45PLS73Kcjs.DeleteBoundaryError)(
|
|
1514
1529
|
`recovery: ${resource} has no delete method on the client \u2014 the boundary is marked available in the plan but the typed delete surface is missing`,
|
|
1515
1530
|
{
|
|
1516
1531
|
operation,
|
|
@@ -1539,14 +1554,14 @@ async function applyRecoveryDeletes(holder, matches, parentId, resource, operati
|
|
|
1539
1554
|
verify = "still-present";
|
|
1540
1555
|
}
|
|
1541
1556
|
} catch (err) {
|
|
1542
|
-
if (err instanceof
|
|
1557
|
+
if (err instanceof _chunk45PLS73Kcjs.NotFoundError) verify = "not-found";
|
|
1543
1558
|
else {
|
|
1544
1559
|
verify = "error";
|
|
1545
|
-
code =
|
|
1560
|
+
code = _chunk45PLS73Kcjs.isAutotaskError.call(void 0, err) ? err.code : "SERVER_ERROR";
|
|
1546
1561
|
}
|
|
1547
1562
|
}
|
|
1548
1563
|
} catch (err) {
|
|
1549
|
-
code =
|
|
1564
|
+
code = _chunk45PLS73Kcjs.isAutotaskError.call(void 0, err) ? err.code : "SERVER_ERROR";
|
|
1550
1565
|
}
|
|
1551
1566
|
deleted.push({ id, verified: verify === "not-found", code });
|
|
1552
1567
|
}
|
|
@@ -1574,7 +1589,7 @@ async function recovery(client, input, opts = {}) {
|
|
|
1574
1589
|
const parentId = resolveParentId(input, entry, resource, operation);
|
|
1575
1590
|
const extra = resolveExtraFilter(input, operation);
|
|
1576
1591
|
const limit = resolveLimit(input, operation);
|
|
1577
|
-
const boundaryNote =
|
|
1592
|
+
const boundaryNote = _chunk45PLS73Kcjs.DELETE_BOUNDARY_NOTES[resource];
|
|
1578
1593
|
const boundary = {
|
|
1579
1594
|
available: boundaryNote === void 0,
|
|
1580
1595
|
reason: _nullishCoalesce(boundaryNote, () => ( null)),
|
|
@@ -1586,7 +1601,7 @@ async function recovery(client, input, opts = {}) {
|
|
|
1586
1601
|
};
|
|
1587
1602
|
const isDelete = action === "delete";
|
|
1588
1603
|
if (isDelete && boundaryNote !== void 0) {
|
|
1589
|
-
throw new (0,
|
|
1604
|
+
throw new (0, _chunk45PLS73Kcjs.DeleteBoundaryError)(
|
|
1590
1605
|
`recovery: the vendor defines no DELETE for ${resource} \u2014 the delete cannot be issued through the API (zero wire was issued)`,
|
|
1591
1606
|
{
|
|
1592
1607
|
operation,
|
|
@@ -1595,10 +1610,10 @@ async function recovery(client, input, opts = {}) {
|
|
|
1595
1610
|
}
|
|
1596
1611
|
);
|
|
1597
1612
|
}
|
|
1598
|
-
const dryRun = _optionalChain([opts, 'optionalAccess',
|
|
1599
|
-
const confirm = _nullishCoalesce(_optionalChain([opts, 'optionalAccess',
|
|
1613
|
+
const dryRun = _optionalChain([opts, 'optionalAccess', _46 => _46.dryRun]) !== false;
|
|
1614
|
+
const confirm = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _47 => _47.confirm]), () => ( input.confirm));
|
|
1600
1615
|
if (isDelete && !dryRun && confirm !== RECOVERY_CONFIRM) {
|
|
1601
|
-
throw new (0,
|
|
1616
|
+
throw new (0, _chunk45PLS73Kcjs.ConfirmationRequiredError)(
|
|
1602
1617
|
`recovery: action 'delete' apply is destructive and requires its confirmation flag: pass confirm: "${RECOVERY_CONFIRM}"`,
|
|
1603
1618
|
{
|
|
1604
1619
|
operation: RECOVERY_CONFIRM,
|
|
@@ -1614,7 +1629,7 @@ async function recovery(client, input, opts = {}) {
|
|
|
1614
1629
|
const query = await holder.queryBounded({ filter: conditions, limit });
|
|
1615
1630
|
if (query.hasMore) {
|
|
1616
1631
|
const wire = isDelete ? "DELETE wire" : "mutating wire";
|
|
1617
|
-
throw new (0,
|
|
1632
|
+
throw new (0, _chunk45PLS73Kcjs.RecoveryTruncatedError)(
|
|
1618
1633
|
`recovery: the marker search on ${resource} TRIPPED its match cap (${limit}) \u2014 more matches exist than were returned (zero ${wire} was issued)`,
|
|
1619
1634
|
{
|
|
1620
1635
|
operation,
|
|
@@ -1643,7 +1658,7 @@ async function recovery(client, input, opts = {}) {
|
|
|
1643
1658
|
return { ...base, simulated: true, dryRun: true };
|
|
1644
1659
|
}
|
|
1645
1660
|
if (unsafeId) {
|
|
1646
|
-
throw new (0,
|
|
1661
|
+
throw new (0, _chunk45PLS73Kcjs.MarkerUnsafeIdError)(
|
|
1647
1662
|
`recovery: ${unsafeIds.length} of ${matches.length} match(es) on ${resource} have ids beyond Number.MAX_SAFE_INTEGER \u2014 they CANNOT be addressed through the SDK's typed delete surface (zero DELETE wire was issued)`,
|
|
1648
1663
|
{
|
|
1649
1664
|
operation,
|
|
@@ -1661,7 +1676,7 @@ function needsConfirmation(record) {
|
|
|
1661
1676
|
return record.effect === "destructive" || (_nullishCoalesce(record.flags, () => ( []))).includes("requiresApproval");
|
|
1662
1677
|
}
|
|
1663
1678
|
function refuse(message, operation, suggestedAction) {
|
|
1664
|
-
throw new (0,
|
|
1679
|
+
throw new (0, _chunk45PLS73Kcjs.ConfirmationRequiredError)(message, { operation, suggestedAction });
|
|
1665
1680
|
}
|
|
1666
1681
|
var MODE_BY_EFFECT = {
|
|
1667
1682
|
read: "read",
|
|
@@ -1707,7 +1722,7 @@ function looseTypeOk(type, value) {
|
|
|
1707
1722
|
case "string[]":
|
|
1708
1723
|
return Array.isArray(value) && value.every((v) => typeof v === "string");
|
|
1709
1724
|
case "object":
|
|
1710
|
-
return
|
|
1725
|
+
return _chunk45PLS73Kcjs.isRecord.call(void 0, value);
|
|
1711
1726
|
default:
|
|
1712
1727
|
return true;
|
|
1713
1728
|
}
|
|
@@ -1721,12 +1736,12 @@ function declaredArgList(record) {
|
|
|
1721
1736
|
function resolveDispatchArgs(record, argsIn) {
|
|
1722
1737
|
const operation = record.id;
|
|
1723
1738
|
const bad = (message) => {
|
|
1724
|
-
throw new (0,
|
|
1739
|
+
throw new (0, _chunk45PLS73Kcjs.AutotaskConfigError)(`invoke: "${operation}" ${message}`, { operation });
|
|
1725
1740
|
};
|
|
1726
1741
|
if (argsIn === void 0 || argsIn === null) return [];
|
|
1727
1742
|
if (Array.isArray(argsIn)) return argsIn;
|
|
1728
1743
|
const byName = argsIn;
|
|
1729
|
-
if (!
|
|
1744
|
+
if (!_chunk45PLS73Kcjs.isRecord.call(void 0, byName) || ![Object.prototype, null].includes(Object.getPrototypeOf(byName))) {
|
|
1730
1745
|
return bad(`args must be a positional array or a plain object of named inputs (declared: ${declaredArgList(record)})`);
|
|
1731
1746
|
}
|
|
1732
1747
|
const schema = _nullishCoalesce(record.inputSchema, () => ( {}));
|
|
@@ -1747,7 +1762,7 @@ function validateDispatchArgs(record, argsIn) {
|
|
|
1747
1762
|
const bagName = names.find((n) => schema[n].properties);
|
|
1748
1763
|
const surplus = args[names.length];
|
|
1749
1764
|
const bagHint = bagName && surplus !== null && typeof surplus === "object" && !Array.isArray(surplus) ? ` \u2014 options go inside the single ${bagName} object` : "";
|
|
1750
|
-
throw new (0,
|
|
1765
|
+
throw new (0, _chunk45PLS73Kcjs.AutotaskConfigError)(
|
|
1751
1766
|
`invoke: "${operation}" declares ${names.length} positional arg(s) (${declaredArgList(record)}) but ${args.length} were passed \u2014 extra args are refused${bagHint}`,
|
|
1752
1767
|
{
|
|
1753
1768
|
operation,
|
|
@@ -1757,7 +1772,7 @@ function validateDispatchArgs(record, argsIn) {
|
|
|
1757
1772
|
}
|
|
1758
1773
|
const required = names.filter((n) => schema[n].required);
|
|
1759
1774
|
if (args.length < required.length) {
|
|
1760
|
-
throw new (0,
|
|
1775
|
+
throw new (0, _chunk45PLS73Kcjs.AutotaskConfigError)(
|
|
1761
1776
|
`invoke: "${operation}" requires ${required.length} positional arg(s) (${required.map((n) => `${n}: ${schema[n].type}`).join(", ")}) but only ${args.length} were passed \u2014 declared args: ${declaredArgList(record)}`,
|
|
1762
1777
|
{ operation }
|
|
1763
1778
|
);
|
|
@@ -1768,7 +1783,7 @@ function validateDispatchArgs(record, argsIn) {
|
|
|
1768
1783
|
const name = names[i];
|
|
1769
1784
|
const spec = schema[name];
|
|
1770
1785
|
if (!looseTypeOk(spec.type, value)) {
|
|
1771
|
-
throw new (0,
|
|
1786
|
+
throw new (0, _chunk45PLS73Kcjs.AutotaskConfigError)(
|
|
1772
1787
|
`invoke: "${operation}" arg ${i + 1} is declared ${name}: ${spec.type} \u2014 the value has the wrong type (pass a ${spec.type} value)`,
|
|
1773
1788
|
{ operation }
|
|
1774
1789
|
);
|
|
@@ -1776,17 +1791,17 @@ function validateDispatchArgs(record, argsIn) {
|
|
|
1776
1791
|
}
|
|
1777
1792
|
}
|
|
1778
1793
|
function foldFlattenedOpts(record, toolArgs) {
|
|
1779
|
-
if (!
|
|
1780
|
-
throw new (0,
|
|
1794
|
+
if (!_chunk45PLS73Kcjs.isRecord.call(void 0, toolArgs)) {
|
|
1795
|
+
throw new (0, _chunk45PLS73Kcjs.AutotaskConfigError)(`invoke: "${record.id}" tool args must be a plain object of named inputs`, { operation: record.id });
|
|
1781
1796
|
}
|
|
1782
|
-
const bagKeys = (_nullishCoalesce(_optionalChain([record, 'access',
|
|
1797
|
+
const bagKeys = (_nullishCoalesce(_optionalChain([record, 'access', _48 => _48.inputSchema, 'optionalAccess', _49 => _49.opts, 'optionalAccess', _50 => _50.properties]), () => ( []))).map((p) => p.name);
|
|
1783
1798
|
const flat = Object.keys(toolArgs).filter((k) => bagKeys.includes(k) && toolArgs[k] !== void 0 && toolArgs[k] !== null);
|
|
1784
1799
|
const folded = { ...toolArgs };
|
|
1785
1800
|
for (const k of bagKeys) delete folded[k];
|
|
1786
1801
|
if (folded.opts === null) delete folded.opts;
|
|
1787
1802
|
if (flat.length === 0) return folded;
|
|
1788
1803
|
if (folded.opts !== void 0) {
|
|
1789
|
-
throw new (0,
|
|
1804
|
+
throw new (0, _chunk45PLS73Kcjs.AutotaskConfigError)(
|
|
1790
1805
|
`invoke: "${record.id}" was given both opts and flattened option(s) ${flat.map((k) => `"${k}"`).join(", ")} \u2014 pass one form`,
|
|
1791
1806
|
{ operation: record.id }
|
|
1792
1807
|
);
|
|
@@ -1796,7 +1811,7 @@ function foldFlattenedOpts(record, toolArgs) {
|
|
|
1796
1811
|
|
|
1797
1812
|
// src/operations/invoke/inputSets.ts
|
|
1798
1813
|
var PARAMS_BAG_KEYS = {
|
|
1799
|
-
query: ["filter", "limit", "includeFields", "via", "latest", "noteChars", "fieldsPreset", "fieldCheck"],
|
|
1814
|
+
query: ["filter", "limit", "includeFields", "via", "latest", "noteChars", "fieldsPreset", "fieldCheck", "names"],
|
|
1800
1815
|
// No registry row DECLARES `queryAll` today (a plan decision: the raw walk is
|
|
1801
1816
|
// called directly), so this entry never fires. It is KEPT so that a future
|
|
1802
1817
|
// `queryAll` row — which `invoke` WOULD dispatch via holder[operation] —
|
|
@@ -1847,12 +1862,12 @@ function validateParamsBag(record, args) {
|
|
|
1847
1862
|
if (record.inputSchemaStrict !== true) return;
|
|
1848
1863
|
const valid = PARAMS_BAG_KEYS[record.operation];
|
|
1849
1864
|
if (valid === void 0) return;
|
|
1850
|
-
const bag = _optionalChain([args, 'optionalAccess',
|
|
1851
|
-
if (bag === void 0 || bag === null || !
|
|
1865
|
+
const bag = _optionalChain([args, 'optionalAccess', _51 => _51[0]]);
|
|
1866
|
+
if (bag === void 0 || bag === null || !_chunk45PLS73Kcjs.isRecord.call(void 0, bag)) return;
|
|
1852
1867
|
const unknown = Object.keys(bag).filter((k) => !valid.includes(k));
|
|
1853
1868
|
if (unknown.length === 0) return;
|
|
1854
1869
|
const suggestions = unknown.map((k) => [k, suggestForKey(k, valid)]).filter((pair) => pair[1] !== null).map(([k, s]) => `"${k}" \u2192 "${s}"`);
|
|
1855
|
-
throw new (0,
|
|
1870
|
+
throw new (0, _chunk45PLS73Kcjs.AutotaskConfigError)(
|
|
1856
1871
|
`invoke: "${record.id}" params bag has unknown key(s) ${unknown.map((k) => `"${k}"`).join(", ")} \u2014 the bag is closed (valid keys: ${valid.join(", ")})`,
|
|
1857
1872
|
{
|
|
1858
1873
|
operation: record.id,
|
|
@@ -1863,17 +1878,17 @@ function validateParamsBag(record, args) {
|
|
|
1863
1878
|
function validateGetBag(record, args) {
|
|
1864
1879
|
if (record.kind !== "primitive" || record.operation !== "get") return;
|
|
1865
1880
|
const at = Object.keys(_nullishCoalesce(record.inputSchema, () => ( {}))).indexOf("opts");
|
|
1866
|
-
const bag = at < 0 ? void 0 : _optionalChain([args, 'optionalAccess',
|
|
1867
|
-
if (bag === void 0 || bag === null || !
|
|
1881
|
+
const bag = at < 0 ? void 0 : _optionalChain([args, 'optionalAccess', _52 => _52[at]]);
|
|
1882
|
+
if (bag === void 0 || bag === null || !_chunk45PLS73Kcjs.isRecord.call(void 0, bag)) return;
|
|
1868
1883
|
const unknown = Object.keys(bag).filter((k) => k !== "fresh");
|
|
1869
1884
|
if (unknown.length > 0) {
|
|
1870
|
-
throw new (0,
|
|
1885
|
+
throw new (0, _chunk45PLS73Kcjs.AutotaskConfigError)(
|
|
1871
1886
|
`invoke: "${record.id}" opts bag has unknown key(s) ${unknown.map((k) => `"${k}"`).join(", ")} \u2014 the bag is closed (valid keys: fresh)`,
|
|
1872
1887
|
{ operation: record.id, suggestedAction: "Pass only { fresh?: boolean }." }
|
|
1873
1888
|
);
|
|
1874
1889
|
}
|
|
1875
1890
|
if (bag.fresh !== void 0 && typeof bag.fresh !== "boolean") {
|
|
1876
|
-
throw new (0,
|
|
1891
|
+
throw new (0, _chunk45PLS73Kcjs.AutotaskConfigError)(
|
|
1877
1892
|
`invoke: fresh must be a boolean (got ${typeof bag.fresh}) \u2014 "${record.id}" was not issued`,
|
|
1878
1893
|
{ operation: record.id, suggestedAction: "Pass fresh: true (bypass the read cache) or omit it." }
|
|
1879
1894
|
);
|
|
@@ -1885,7 +1900,7 @@ function validateInvokeOptions(opts, operation) {
|
|
|
1885
1900
|
const unknown = Object.keys(opts).filter((k) => !INVOKE_OPTION_KEYS.includes(k));
|
|
1886
1901
|
if (unknown.length === 0) return;
|
|
1887
1902
|
const suggestions = unknown.map((k) => [k, suggestForKey(k, ["dryRun", "confirm", "lastModifiedDate", "maxRetries", "fresh"])]).filter((pair) => pair[1] !== null).map(([k, s]) => `"${k}" \u2192 "${s}"`);
|
|
1888
|
-
throw new (0,
|
|
1903
|
+
throw new (0, _chunk45PLS73Kcjs.AutotaskConfigError)(
|
|
1889
1904
|
`invoke: "${operation}" has unknown option key(s) ${unknown.map((k) => `"${k}"`).join(", ")} \u2014 the options set is closed (valid: dryRun, confirm, lastModifiedDate, maxRetries, fresh; "mode" is internal to the mode wrappers)`,
|
|
1890
1905
|
{
|
|
1891
1906
|
operation,
|
|
@@ -1898,7 +1913,7 @@ function unknownKeysRefusal(raw, validKeys, subject, operation) {
|
|
|
1898
1913
|
const unknown = Object.keys(raw).filter((k) => !validKeys.includes(k));
|
|
1899
1914
|
if (unknown.length === 0) return null;
|
|
1900
1915
|
const suggestions = unknown.map((k) => [k, suggestForKey(k, [...validKeys])]).filter((pair) => pair[1] !== null).map(([k, s]) => `"${k}" \u2192 "${s}"`);
|
|
1901
|
-
return new (0,
|
|
1916
|
+
return new (0, _chunk45PLS73Kcjs.AutotaskConfigError)(
|
|
1902
1917
|
`unknown ${subject} ${unknown.map((k) => `"${k}"`).join(", ")} \u2014 the ${subject} set is closed (valid keys: ${validKeys.join(", ")})`,
|
|
1903
1918
|
{
|
|
1904
1919
|
...operation !== void 0 ? { operation } : {},
|
|
@@ -1908,7 +1923,7 @@ function unknownKeysRefusal(raw, validKeys, subject, operation) {
|
|
|
1908
1923
|
}
|
|
1909
1924
|
|
|
1910
1925
|
// src/operations/invoke/registry.ts
|
|
1911
|
-
var RECORDS =
|
|
1926
|
+
var RECORDS = _chunkRAZEXOLCcjs.CAPABILITIES;
|
|
1912
1927
|
var byId2 = new Map(RECORDS.map((r) => [r.id, r]));
|
|
1913
1928
|
|
|
1914
1929
|
// src/operations/invoke/dispatch.ts
|
|
@@ -1927,7 +1942,7 @@ function bufferResult(buf) {
|
|
|
1927
1942
|
function resolveRecord(operation) {
|
|
1928
1943
|
const record = byId2.get(operation);
|
|
1929
1944
|
if (record === void 0) {
|
|
1930
|
-
throw new (0,
|
|
1945
|
+
throw new (0, _chunk45PLS73Kcjs.AutotaskConfigError)(
|
|
1931
1946
|
`invoke: unknown operation "${operation}" \u2014 it is not in the capability registry`,
|
|
1932
1947
|
{ operation, suggestedAction: "List the registry (the ./capabilities subpath) for the exact operation key." }
|
|
1933
1948
|
);
|
|
@@ -1938,30 +1953,30 @@ function governPreRequest(record, operation, opts) {
|
|
|
1938
1953
|
validateInvokeOptions(opts, operation);
|
|
1939
1954
|
const mode = opts.mode;
|
|
1940
1955
|
if (mode !== void 0 && MODE_BY_EFFECT[record.effect] !== mode) {
|
|
1941
|
-
throw new (0,
|
|
1956
|
+
throw new (0, _chunk45PLS73Kcjs.AutotaskConfigError)(crossModeRefusal(operation, record.effect, mode), { operation });
|
|
1942
1957
|
}
|
|
1943
1958
|
if (opts.dryRun !== void 0 && typeof opts.dryRun !== "boolean") {
|
|
1944
|
-
throw new (0,
|
|
1959
|
+
throw new (0, _chunk45PLS73Kcjs.AutotaskConfigError)(
|
|
1945
1960
|
`invoke: dryRun must be a boolean (got ${typeof opts.dryRun}) \u2014 "${operation}" was not issued`,
|
|
1946
1961
|
{ operation, suggestedAction: "Pass dryRun: true (simulate) or dryRun: false (apply) as a real boolean." }
|
|
1947
1962
|
);
|
|
1948
1963
|
}
|
|
1949
1964
|
if (opts.fresh !== void 0) {
|
|
1950
1965
|
if (typeof opts.fresh !== "boolean") {
|
|
1951
|
-
throw new (0,
|
|
1966
|
+
throw new (0, _chunk45PLS73Kcjs.AutotaskConfigError)(
|
|
1952
1967
|
`invoke: fresh must be a boolean (got ${typeof opts.fresh}) \u2014 "${operation}" was not issued`,
|
|
1953
1968
|
{ operation, suggestedAction: "Pass fresh: true (bypass the read cache) or omit it." }
|
|
1954
1969
|
);
|
|
1955
1970
|
}
|
|
1956
1971
|
if (record.effect !== "read" || record.kind !== "primitive" || record.operation !== "get" || !("opts" in (_nullishCoalesce(record.inputSchema, () => ( {}))))) {
|
|
1957
|
-
throw new (0,
|
|
1972
|
+
throw new (0, _chunk45PLS73Kcjs.AutotaskConfigError)(
|
|
1958
1973
|
`invoke: fresh applies only to a single-record "<resource>.get" read \u2014 "${operation}" was not issued`,
|
|
1959
1974
|
{ operation, suggestedAction: "Drop the fresh option (only <resource>.get consults the read cache per call)." }
|
|
1960
1975
|
);
|
|
1961
1976
|
}
|
|
1962
1977
|
}
|
|
1963
1978
|
if (record.effect === "read" && opts.dryRun === true) {
|
|
1964
|
-
throw new (0,
|
|
1979
|
+
throw new (0, _chunk45PLS73Kcjs.AutotaskConfigError)(
|
|
1965
1980
|
`invoke: "${operation}" is a read \u2014 dryRun is not applicable (reads issue their request as-is)`,
|
|
1966
1981
|
{ operation }
|
|
1967
1982
|
);
|
|
@@ -1978,7 +1993,7 @@ function operationsHolder(client) {
|
|
|
1978
1993
|
return {
|
|
1979
1994
|
resolveAny: (identifier, opts) => resolveAny(client, identifier, opts),
|
|
1980
1995
|
searchAcrossResources: (query, opts) => searchAcrossResources(client, query, opts),
|
|
1981
|
-
fetchMany: (items, opts) =>
|
|
1996
|
+
fetchMany: (items, opts) => _chunk45PLS73Kcjs.fetchMany.call(void 0, client, items, opts),
|
|
1982
1997
|
// Issue #62: the generic aggregate + the cheap count — the
|
|
1983
1998
|
// groupBy/sum-absent mode is ONE vendor /query/count (the S12-C blind
|
|
1984
1999
|
// sentinel rides through); the group/sum modes walk the named
|
|
@@ -1990,12 +2005,12 @@ function operationsHolder(client) {
|
|
|
1990
2005
|
// Issue #59 PR-B: the bulk fetch by ids — query-first chunked `id in`
|
|
1991
2006
|
// reads + the per-id `get` fallback (blind-surface-safe; per-item
|
|
1992
2007
|
// typed outcomes reuse the fetchMany shapes).
|
|
1993
|
-
fetchByIds: (items, opts) =>
|
|
2008
|
+
fetchByIds: (items, opts) => _chunk45PLS73Kcjs.fetchByIds.call(void 0, client, items, opts),
|
|
1994
2009
|
// Issue #65: opt-in resource name expansion — per-id resources.get
|
|
1995
2010
|
// reads ONLY (never an id-in query — the resources table can be blind
|
|
1996
2011
|
// to count/query while per-id reads work); blind-marked rows for ids
|
|
1997
2012
|
// the API user cannot resolve; the name cache (default-on).
|
|
1998
|
-
expandResourceNames: (ids, opts) =>
|
|
2013
|
+
expandResourceNames: (ids, opts) => _chunk45PLS73Kcjs.expandResourceNames.call(void 0, client, ids, opts),
|
|
1999
2014
|
relationshipMap: (resourceKey) => relationshipMap(client, resourceKey),
|
|
2000
2015
|
// Issue #11: the served blind-surface inventory (zero wire) + the
|
|
2001
2016
|
// bounded caller-opted reachability sweep (read-only, confirmProbe-
|
|
@@ -2005,12 +2020,12 @@ function operationsHolder(client) {
|
|
|
2005
2020
|
// Issue #12: the served zone-fact create-guidance catalog (zero wire).
|
|
2006
2021
|
createGuidance: (opts) => createGuidance(client, opts),
|
|
2007
2022
|
// Issue #202: ExecuteCommand deep links — pure, zero wire.
|
|
2008
|
-
uiLink: (input) =>
|
|
2023
|
+
uiLink: (input) => _chunk45PLS73Kcjs.uiLink.call(void 0, client, input),
|
|
2009
2024
|
// Issue #31: the opt-in live field-metadata channel — N bounded
|
|
2010
2025
|
// entityInformation GETs (the op's own cap refuses over-cap fan-outs
|
|
2011
2026
|
// pre-request; per-resource failures are recorded on the row and
|
|
2012
2027
|
// never abort the call).
|
|
2013
|
-
fieldCatalog: (opts) =>
|
|
2028
|
+
fieldCatalog: (opts) => _chunk45PLS73Kcjs.fieldCatalog.call(void 0, client, opts),
|
|
2014
2029
|
// Issue #9: the one-call recovery/cleanup op — effect write in the
|
|
2015
2030
|
// registry (the governor's dry-run-first applies to it); the op's own
|
|
2016
2031
|
// confirm gate makes the destructive action deliberate (the governor
|
|
@@ -2020,15 +2035,15 @@ function operationsHolder(client) {
|
|
|
2020
2035
|
}
|
|
2021
2036
|
function resolveHolder(client, record, operation) {
|
|
2022
2037
|
const clientBag = client;
|
|
2023
|
-
let holder = clientBag[
|
|
2038
|
+
let holder = clientBag[_chunk45PLS73Kcjs.camelKey.call(void 0, record.resource)];
|
|
2024
2039
|
if (typeof holder === "function") {
|
|
2025
|
-
holder = _nullishCoalesce(clientBag[`${
|
|
2040
|
+
holder = _nullishCoalesce(clientBag[`${_chunk45PLS73Kcjs.camelKey.call(void 0, record.resource)}Resource`], () => ( holder));
|
|
2026
2041
|
}
|
|
2027
2042
|
if (holder === void 0 && record.resource === "operations") {
|
|
2028
2043
|
holder = operationsHolder(client);
|
|
2029
2044
|
}
|
|
2030
2045
|
if (holder === void 0) {
|
|
2031
|
-
throw new (0,
|
|
2046
|
+
throw new (0, _chunk45PLS73Kcjs.AutotaskConfigError)(
|
|
2032
2047
|
`invoke: the client exposes no accessor for resource "${record.resource}"`,
|
|
2033
2048
|
{ operation }
|
|
2034
2049
|
);
|
|
@@ -2088,11 +2103,12 @@ async function invokeMode(client, operation, argsIn = [], opts = {}) {
|
|
|
2088
2103
|
const boundedQuery = record.kind === "primitive" && record.operation === "query";
|
|
2089
2104
|
const countedQuery = record.kind === "primitive" && record.operation === "count";
|
|
2090
2105
|
const holder = resolveHolder(client, record, operation);
|
|
2091
|
-
if (boundedQuery || countedQuery) await
|
|
2106
|
+
if (boundedQuery || countedQuery) await _chunk45PLS73Kcjs.validateQueryFieldNames.call(void 0, record, holder, args);
|
|
2107
|
+
const labelQuery = boundedQuery && _chunk45PLS73Kcjs.readNamesOpt.call(void 0, _optionalChain([args, 'access', _53 => _53[0], 'optionalAccess', _54 => _54["names"]]), `invoke: "${record.id}" params bag`);
|
|
2092
2108
|
const methodName = boundedQuery ? "queryBounded" : record.operation;
|
|
2093
2109
|
const method = holder[methodName];
|
|
2094
2110
|
if (typeof method !== "function") {
|
|
2095
|
-
throw new (0,
|
|
2111
|
+
throw new (0, _chunk45PLS73Kcjs.AutotaskConfigError)(
|
|
2096
2112
|
`invoke: "${record.resource}.${methodName}" is not a callable method on the client`,
|
|
2097
2113
|
{ operation }
|
|
2098
2114
|
);
|
|
@@ -2102,6 +2118,11 @@ async function invokeMode(client, operation, argsIn = [], opts = {}) {
|
|
|
2102
2118
|
const callArgs = buildCallArgs(record, args, mutationOpts, isWrite);
|
|
2103
2119
|
if (opts.fresh === true) appendFresh(record, callArgs);
|
|
2104
2120
|
const result = await method.apply(holder, callArgs);
|
|
2121
|
+
if (labelQuery && Array.isArray(_optionalChain([result, 'optionalAccess', _55 => _55.items]))) {
|
|
2122
|
+
const bounded = result;
|
|
2123
|
+
const labelled = await _chunk45PLS73Kcjs.labelRows.call(void 0, client, record.resource, bounded.items);
|
|
2124
|
+
return { ...bounded, items: labelled.rows, ...labelled.names !== void 0 ? { names: labelled.names } : {} };
|
|
2125
|
+
}
|
|
2105
2126
|
return Buffer.isBuffer(result) ? bufferResult(result) : result;
|
|
2106
2127
|
}
|
|
2107
2128
|
|
|
@@ -2171,4 +2192,5 @@ async function invokeDelete(client, operation, args = [], opts = {}) {
|
|
|
2171
2192
|
|
|
2172
2193
|
|
|
2173
2194
|
|
|
2174
|
-
|
|
2195
|
+
|
|
2196
|
+
exports.AGGREGATE_DATE_BUCKETS = AGGREGATE_DATE_BUCKETS; exports.AGGREGATE_DEFAULT_LIMIT = AGGREGATE_DEFAULT_LIMIT; exports.AGGREGATE_DEFAULT_TOP = AGGREGATE_DEFAULT_TOP; exports.AGGREGATE_TOP_MAX = AGGREGATE_TOP_MAX; exports.BLIND_SURFACE_KINDS = BLIND_SURFACE_KINDS; exports.CREATE_BLOCKER_KINDS = CREATE_BLOCKER_KINDS; exports.ENTITY_TYPE_TO_RESOURCE = _chunk45PLS73Kcjs.ENTITY_TYPE_TO_RESOURCE; exports.EXPAND_RESOURCE_NAMES_MAX_IDS = _chunk45PLS73Kcjs.EXPAND_RESOURCE_NAMES_MAX_IDS; exports.FETCH_BY_IDS_CHUNK_SIZE = _chunk45PLS73Kcjs.FETCH_BY_IDS_CHUNK_SIZE; exports.FETCH_BY_IDS_MAX_ITEMS = _chunk45PLS73Kcjs.FETCH_BY_IDS_MAX_ITEMS; exports.FETCH_MANY_MAX_ITEMS = _chunk45PLS73Kcjs.FETCH_MANY_MAX_ITEMS; exports.FIELD_CACHE_KINDS = _chunk45PLS73Kcjs.FIELD_CACHE_KINDS; exports.FIELD_CATALOG_HONESTY_NOTE = _chunk45PLS73Kcjs.FIELD_CATALOG_HONESTY_NOTE; exports.INVOKE_OPTION_KEYS = INVOKE_OPTION_KEYS; exports.MAX_FIELD_CATALOG_WIRE = _chunk45PLS73Kcjs.MAX_FIELD_CATALOG_WIRE; exports.MIN_FIELD_CATALOG_MAX_BYTES = _chunk45PLS73Kcjs.MIN_FIELD_CATALOG_MAX_BYTES; exports.PARAMS_BAG_KEYS = PARAMS_BAG_KEYS; exports.PICKLIST_VALUE_NOT_SERVED_NOTE = _chunk45PLS73Kcjs.PICKLIST_VALUE_NOT_SERVED_NOTE; exports.RECOVERY_CONFIRM = RECOVERY_CONFIRM; exports.RECOVERY_DEFAULT_LIMIT = RECOVERY_DEFAULT_LIMIT; exports.RECOVERY_MAX_LIMIT = RECOVERY_MAX_LIMIT; exports.UI_LINK_ENTITIES = _chunk45PLS73Kcjs.UI_LINK_ENTITIES; exports.WORKFLOW_RESOURCES = _chunk45PLS73Kcjs.WORKFLOW_RESOURCES; exports.aggregate = aggregate; exports.blindSurfaces = blindSurfaces; exports.buildUiLink = _chunk45PLS73Kcjs.buildUiLink; exports.createGuidance = createGuidance; exports.dateBucketLabel = dateBucketLabel; exports.effectiveRequiredFields = _chunk45PLS73Kcjs.effectiveRequiredFields; exports.expandResourceNames = _chunk45PLS73Kcjs.expandResourceNames; exports.fetchByIds = _chunk45PLS73Kcjs.fetchByIds; exports.fetchMany = _chunk45PLS73Kcjs.fetchMany; exports.fieldCatalog = _chunk45PLS73Kcjs.fieldCatalog; exports.foldFlattenedOpts = foldFlattenedOpts; exports.invoke = invoke; exports.invokeDelete = invokeDelete; exports.invokeRead = invokeRead; exports.invokeWrite = invokeWrite; exports.isEnumerableResource = _chunk45PLS73Kcjs.isEnumerableResource; exports.needsConfirmation = needsConfirmation; exports.probeReachability = probeReachability; exports.recovery = recovery; exports.relationshipMap = relationshipMap; exports.resolveAny = resolveAny; exports.resourceForEntityType = _chunk45PLS73Kcjs.resourceForEntityType; exports.revenueRollup = revenueRollup; exports.searchAcrossResources = searchAcrossResources; exports.uiLink = _chunk45PLS73Kcjs.uiLink; exports.unknownKeysRefusal = unknownKeysRefusal; exports.validateDispatchArgs = validateDispatchArgs; exports.validateFetchManyItems = _chunk45PLS73Kcjs.validateFetchManyItems; exports.validateInvokeOptions = validateInvokeOptions; exports.validateParamsBag = validateParamsBag;
|