node-autotask 0.92.0 → 0.92.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/MCP_TOOL_CATALOG.json +1 -1
- package/capabilities.json +4 -4
- package/dist/capabilities-data.js +3 -3
- package/dist/{chunk-NQNAEA23.js → chunk-4BICEQ4S.js} +578 -295
- package/dist/{chunk-ELAU2MT5.js → chunk-C7KZ7PB3.js} +2 -2
- package/dist/{chunk-JPZ7M7QI.cjs → chunk-JY6BQUPO.cjs} +200 -198
- package/dist/{chunk-H24SV774.cjs → chunk-LYAHXYZR.cjs} +579 -294
- package/dist/{chunk-ATDGRAX2.cjs → chunk-QC45KFQQ.cjs} +30 -30
- package/dist/{chunk-XAOWO42G.js → chunk-QVDXIXY4.js} +3 -1
- package/dist/{index-B9y5IwT1.d.cts → index-B0p5O-2e.d.cts} +30 -2
- package/dist/{index-B9y5IwT1.d.ts → index-B0p5O-2e.d.ts} +30 -2
- package/dist/{index-U7Lepdm2.d.ts → index-it9IqLsM.d.ts} +6 -1
- package/dist/{index-lWek2NrV.d.cts → index-opnSlg90.d.cts} +6 -1
- package/dist/index.cjs +88 -84
- package/dist/index.d.cts +8 -4
- package/dist/index.d.ts +8 -4
- package/dist/index.js +4 -4
- package/dist/operations/index.cjs +50 -50
- package/dist/operations/index.d.cts +7 -4
- package/dist/operations/index.d.ts +7 -4
- package/dist/operations/index.js +1 -1
- package/dist/pool.cjs +11 -11
- package/dist/pool.d.cts +1 -1
- package/dist/pool.d.ts +1 -1
- package/dist/pool.js +3 -3
- package/dist/resources/index.cjs +26 -26
- package/dist/resources/index.d.cts +2 -2
- package/dist/resources/index.d.ts +2 -2
- package/dist/resources/index.js +2 -2
- package/dist/types/index.d.cts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/docs/API.md +36 -0
- package/package.json +1 -1
|
@@ -2,6 +2,7 @@ import { loadCapabilityRecords } from './chunk-2MC3LDZU.js';
|
|
|
2
2
|
import { NoopLogger, REDACTED, deepMarkUntrusted, wrapUntrusted } from './chunk-X6VWD6WW.js';
|
|
3
3
|
import { randomUUID, createHash } from 'crypto';
|
|
4
4
|
import { AsyncLocalStorage } from 'async_hooks';
|
|
5
|
+
import { types } from 'util';
|
|
5
6
|
|
|
6
7
|
// src/errors/base.ts
|
|
7
8
|
function nextActionFor(code, opts = {}) {
|
|
@@ -1440,6 +1441,7 @@ function resolveConfig(config) {
|
|
|
1440
1441
|
}
|
|
1441
1442
|
|
|
1442
1443
|
// src/http/types.ts
|
|
1444
|
+
var INVENTORY_APPROVAL_PRODUCT_ID = /* @__PURE__ */ Symbol("inventoryApprovalProductId");
|
|
1443
1445
|
var IDEMPOTENT_METHODS = ["GET", "PUT", "DELETE"];
|
|
1444
1446
|
var AUDIT_DECIMAL_ID = /^(?:0|[1-9]\d{0,18})$/;
|
|
1445
1447
|
var MAX_AUDIT_ID = "9223372036854775807";
|
|
@@ -17801,7 +17803,8 @@ var HttpClient = class {
|
|
|
17801
17803
|
}
|
|
17802
17804
|
let parsed;
|
|
17803
17805
|
try {
|
|
17804
|
-
|
|
17806
|
+
const decodeTarget = opts[INVENTORY_APPROVAL_PRODUCT_ID] === true ? "item" : s.recordTarget;
|
|
17807
|
+
parsed = decodeResponseJson(text, s.auditTarget, decodeTarget, decodeURIComponent(s.opts.path));
|
|
17805
17808
|
} catch {
|
|
17806
17809
|
return this.handleNonJson2xx(s, res, status, text);
|
|
17807
17810
|
}
|
|
@@ -18457,6 +18460,502 @@ function slimCompany(row) {
|
|
|
18457
18460
|
return { id: row.id, companyName: row.companyName, isActive: row.isActive, parentCompanyID: row.parentCompanyID };
|
|
18458
18461
|
}
|
|
18459
18462
|
|
|
18463
|
+
// src/resources/base/helpers.ts
|
|
18464
|
+
function describeResponseShape(body) {
|
|
18465
|
+
if (body === null) return "null";
|
|
18466
|
+
if (Array.isArray(body)) return `array(len=${body.length})`;
|
|
18467
|
+
if (typeof body !== "object") return typeof body;
|
|
18468
|
+
const rec = body;
|
|
18469
|
+
const keys = Object.keys(rec).sort();
|
|
18470
|
+
const typeOf = (v) => v === null ? "null" : Array.isArray(v) ? "array" : typeof v;
|
|
18471
|
+
const parts = keys.slice(0, 16).map((k) => `${k}:${typeOf(rec[k])}`);
|
|
18472
|
+
const more = keys.length > 16 ? `, +${keys.length - 16} more` : "";
|
|
18473
|
+
return `{ ${parts.join(", ")}${more} }`;
|
|
18474
|
+
}
|
|
18475
|
+
function defaultMarkerToken(data) {
|
|
18476
|
+
for (const field of ["name", "title"]) {
|
|
18477
|
+
const v = data[field];
|
|
18478
|
+
if (typeof v === "string" && v.trim() !== "") return v.trim();
|
|
18479
|
+
}
|
|
18480
|
+
return null;
|
|
18481
|
+
}
|
|
18482
|
+
var CONTEXT_ABSENT_MARKER = "#context-absent";
|
|
18483
|
+
function contextAbsentKey(path) {
|
|
18484
|
+
return path + "\0context-absent";
|
|
18485
|
+
}
|
|
18486
|
+
function noteCharsTruncationMarker(charsRemoved) {
|
|
18487
|
+
return `\u2026 [+${charsRemoved} chars truncated]`;
|
|
18488
|
+
}
|
|
18489
|
+
function truncateNoteChars(items, cap, fields) {
|
|
18490
|
+
let truncated = 0;
|
|
18491
|
+
const out = items.map((item) => {
|
|
18492
|
+
if (!isRecord2(item)) return item;
|
|
18493
|
+
let changed = false;
|
|
18494
|
+
const copy = { ...item };
|
|
18495
|
+
for (const field of fields) {
|
|
18496
|
+
const v = copy[field];
|
|
18497
|
+
if (typeof v === "string" && v !== REDACTED && v.length > cap) {
|
|
18498
|
+
const end = cap > 0 && (v.charCodeAt(cap - 1) & 64512) === 55296 ? cap - 1 : cap;
|
|
18499
|
+
copy[field] = v.slice(0, end) + noteCharsTruncationMarker(v.length - end);
|
|
18500
|
+
truncated += 1;
|
|
18501
|
+
changed = true;
|
|
18502
|
+
}
|
|
18503
|
+
}
|
|
18504
|
+
return changed ? copy : item;
|
|
18505
|
+
});
|
|
18506
|
+
return [out, truncated];
|
|
18507
|
+
}
|
|
18508
|
+
function blindEmptyReason(stamp) {
|
|
18509
|
+
return {
|
|
18510
|
+
surface: stamp.surface,
|
|
18511
|
+
kind: "blind-surface",
|
|
18512
|
+
note: stamp.note,
|
|
18513
|
+
authority: stamp.authority,
|
|
18514
|
+
remedy: "the note is the remedy \u2014 the authority op answers for a record"
|
|
18515
|
+
};
|
|
18516
|
+
}
|
|
18517
|
+
function attachUpdateTargetMissReason(err, key) {
|
|
18518
|
+
const pinned = EMPTY_REASON_STAMPS[key]?.update;
|
|
18519
|
+
if (pinned === void 0) return;
|
|
18520
|
+
err.details = { ...err.details ?? {}, emptyReason: pinned };
|
|
18521
|
+
}
|
|
18522
|
+
function buildDryRunResult(spec, policy) {
|
|
18523
|
+
if (spec.operation === "") {
|
|
18524
|
+
throw new AutotaskConfigError("dry-run: the operation name is required");
|
|
18525
|
+
}
|
|
18526
|
+
const wouldApply = spec.checks.every((check) => check.ok);
|
|
18527
|
+
const resource = spec.operation.split(".")[0] ?? spec.operation;
|
|
18528
|
+
const diffPart = spec.diff !== void 0 ? {
|
|
18529
|
+
diff: spec.diff.map((entry) => {
|
|
18530
|
+
if (entry.to === void 0) return entry;
|
|
18531
|
+
const to = isRedactedFieldName(entry.field, policy) ? REDACTED : redactResponseBody(entry.to, policy);
|
|
18532
|
+
return { ...entry, to };
|
|
18533
|
+
})
|
|
18534
|
+
} : {};
|
|
18535
|
+
const dataPart = spec.data !== void 0 ? { data: redactResponseBody(spec.data, policy) } : {};
|
|
18536
|
+
return {
|
|
18537
|
+
operation: spec.operation,
|
|
18538
|
+
wouldApply,
|
|
18539
|
+
target: { resource, ids: spec.ids },
|
|
18540
|
+
request: { method: spec.method, path: spec.path },
|
|
18541
|
+
...diffPart,
|
|
18542
|
+
checks: spec.checks,
|
|
18543
|
+
impact: spec.impact,
|
|
18544
|
+
simulated: true,
|
|
18545
|
+
warnings: spec.warnings ?? [],
|
|
18546
|
+
...dataPart,
|
|
18547
|
+
...spec.emptyReason !== void 0 ? { emptyReason: spec.emptyReason } : {}
|
|
18548
|
+
};
|
|
18549
|
+
}
|
|
18550
|
+
function computeFieldDiff(current, data) {
|
|
18551
|
+
const out = [];
|
|
18552
|
+
for (const [field, to] of Object.entries(data)) {
|
|
18553
|
+
if (field === "id" || to === void 0) continue;
|
|
18554
|
+
const from = Object.hasOwn(current, field) ? current[field] : void 0;
|
|
18555
|
+
if (from !== void 0 && JSON.stringify(from) === JSON.stringify(to)) continue;
|
|
18556
|
+
out.push({ field, from: from === void 0 ? null : from, to });
|
|
18557
|
+
}
|
|
18558
|
+
return out;
|
|
18559
|
+
}
|
|
18560
|
+
function mergePartialBody(current, data) {
|
|
18561
|
+
const merged = { ...current };
|
|
18562
|
+
for (const [key, value] of Object.entries(data)) {
|
|
18563
|
+
if (value === void 0) continue;
|
|
18564
|
+
merged[key] = value;
|
|
18565
|
+
}
|
|
18566
|
+
return merged;
|
|
18567
|
+
}
|
|
18568
|
+
function snapshotMutationOptions(options) {
|
|
18569
|
+
const { dryRun, lastModifiedDate, maxRetries, raw, verifyPersisted } = options ?? {};
|
|
18570
|
+
if (dryRun !== void 0 && typeof dryRun !== "boolean") {
|
|
18571
|
+
throw new AutotaskConfigError("dryRun must be a boolean");
|
|
18572
|
+
}
|
|
18573
|
+
return { dryRun, lastModifiedDate, maxRetries, raw, verifyPersisted };
|
|
18574
|
+
}
|
|
18575
|
+
function normalizeUdfInput(value) {
|
|
18576
|
+
if (Array.isArray(value)) {
|
|
18577
|
+
return value.map((entry) => {
|
|
18578
|
+
if (!isRecord2(entry) || typeof entry.name !== "string" || entry.name === "") {
|
|
18579
|
+
throw new AutotaskConfigError("userDefinedFields array entries must be { name, value } objects");
|
|
18580
|
+
}
|
|
18581
|
+
return { name: entry.name, value: entry.value };
|
|
18582
|
+
});
|
|
18583
|
+
}
|
|
18584
|
+
if (isRecord2(value)) {
|
|
18585
|
+
return Object.entries(value).map(([name, entryValue]) => ({ name, value: entryValue }));
|
|
18586
|
+
}
|
|
18587
|
+
throw new AutotaskConfigError("userDefinedFields must be an array of { name, value } entries or a name-to-value map");
|
|
18588
|
+
}
|
|
18589
|
+
function blindStampFor(stamp, filter) {
|
|
18590
|
+
if (stamp === void 0) return void 0;
|
|
18591
|
+
if (stamp.kind !== "unfiltered-blind") return stamp;
|
|
18592
|
+
const conditions = normalizedConditions(filter);
|
|
18593
|
+
return conditions === void 0 || conditions.length === 0 ? stamp : void 0;
|
|
18594
|
+
}
|
|
18595
|
+
function decodeFileData(body) {
|
|
18596
|
+
if (isRecord2(body)) {
|
|
18597
|
+
const data = body.data;
|
|
18598
|
+
if (typeof data === "string") return Buffer.from(data, "base64");
|
|
18599
|
+
if (Array.isArray(data) && data.every((b) => typeof b === "number")) {
|
|
18600
|
+
return Buffer.from(data);
|
|
18601
|
+
}
|
|
18602
|
+
}
|
|
18603
|
+
if (typeof body === "string") return Buffer.from(body, "base64");
|
|
18604
|
+
throw new AutotaskError(
|
|
18605
|
+
"Expected the file envelope FileQueryResultModel { data } (or a base64 string); got a different shape",
|
|
18606
|
+
{ code: "INVALID_RESPONSE", category: "server" }
|
|
18607
|
+
);
|
|
18608
|
+
}
|
|
18609
|
+
var DEPLURAL_EXCEPTIONS = {
|
|
18610
|
+
tag_aliase: "tag_alias"
|
|
18611
|
+
};
|
|
18612
|
+
function entityNameFromPath(resourcePath) {
|
|
18613
|
+
const segment = resourcePath.slice(resourcePath.lastIndexOf("/") + 1);
|
|
18614
|
+
const snake = segment.replace(/([A-Z])/g, (_m, c, i) => (i > 0 ? `_` : "") + c.toLowerCase()).replace(/_{2,}/g, "_");
|
|
18615
|
+
if (snake.endsWith("ies")) return `${snake.slice(0, -3)}y`;
|
|
18616
|
+
if (snake.endsWith("s")) {
|
|
18617
|
+
const stripped = snake.slice(0, -1);
|
|
18618
|
+
return DEPLURAL_EXCEPTIONS[stripped] ?? stripped;
|
|
18619
|
+
}
|
|
18620
|
+
return snake;
|
|
18621
|
+
}
|
|
18622
|
+
|
|
18623
|
+
// src/resources/special/inventoryItems.ts
|
|
18624
|
+
var REFERENCES = ["inventoryLocationID", "productID"];
|
|
18625
|
+
var QUANTITIES = ["quantityMinimum", "quantityMaximum", "quantityOnHand"];
|
|
18626
|
+
var TEXT_FIELDS = ["bin", "referenceNumber"];
|
|
18627
|
+
var MUTATION_OPTIONS = ["dryRun", "lastModifiedDate", "maxRetries", "raw", "verifyPersisted", "expectedInventoryFacts"];
|
|
18628
|
+
function fail(message) {
|
|
18629
|
+
throw new AutotaskConfigError(`inventory_items: ${message}`);
|
|
18630
|
+
}
|
|
18631
|
+
function own(record, field) {
|
|
18632
|
+
return Object.hasOwn(record, field) ? record[field] : void 0;
|
|
18633
|
+
}
|
|
18634
|
+
function int32(value, label, minimum = -2147483648) {
|
|
18635
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < minimum || value > 2147483647) {
|
|
18636
|
+
fail(`${label} must be an integer between ${minimum} and 2147483647`);
|
|
18637
|
+
}
|
|
18638
|
+
return value;
|
|
18639
|
+
}
|
|
18640
|
+
function inventoryItemId(value) {
|
|
18641
|
+
const id = parseIdentifier(value, "inventory_items: id");
|
|
18642
|
+
if (!isAuditDecimalId(String(id))) fail("id must fit a signed 64-bit integer");
|
|
18643
|
+
return id;
|
|
18644
|
+
}
|
|
18645
|
+
function admitInventoryItem(value, creating) {
|
|
18646
|
+
if (!isRecord2(value) || ![Object.prototype, null].includes(Object.getPrototypeOf(value))) fail("data must be a plain record");
|
|
18647
|
+
const body = captureInventoryPayload(value)();
|
|
18648
|
+
const writable = [...QUANTITIES, ...TEXT_FIELDS, ...creating ? REFERENCES : []];
|
|
18649
|
+
for (const field of Object.keys(body)) {
|
|
18650
|
+
if (!writable.some((name) => name === field)) fail(`${field} is not a writable InventoryItems field on ${creating ? "create" : "update"}`);
|
|
18651
|
+
}
|
|
18652
|
+
if (!creating && Object.keys(body).length === 0) fail("update must contain a writable field");
|
|
18653
|
+
if (creating) for (const field of REFERENCES) int32(own(body, field), field, 1);
|
|
18654
|
+
for (const field of QUANTITIES) {
|
|
18655
|
+
const nonnegative = field === "quantityMinimum" || creating && field === "quantityOnHand";
|
|
18656
|
+
if (creating || Object.hasOwn(body, field)) int32(own(body, field), field, nonnegative ? 0 : void 0);
|
|
18657
|
+
}
|
|
18658
|
+
for (const field of TEXT_FIELDS) {
|
|
18659
|
+
const text = own(body, field);
|
|
18660
|
+
if (Object.hasOwn(body, field) && (typeof text !== "string" || text.length > 50)) fail(`${field} must be a string of at most 50 characters`);
|
|
18661
|
+
}
|
|
18662
|
+
assertQuantityRange(own(body, "quantityMinimum"), own(body, "quantityMaximum"));
|
|
18663
|
+
return body;
|
|
18664
|
+
}
|
|
18665
|
+
function captureInventoryPayload(value) {
|
|
18666
|
+
if (types.isProxy(value)) fail("payload must not be a Proxy");
|
|
18667
|
+
if (!isRecord2(value) || ![Object.prototype, null].includes(Object.getPrototypeOf(value))) fail("data must be a plain record");
|
|
18668
|
+
const descriptors = Object.getOwnPropertyDescriptors(value);
|
|
18669
|
+
const captured = /* @__PURE__ */ Object.create(null);
|
|
18670
|
+
const accessors = [];
|
|
18671
|
+
for (const [field, descriptor2] of Object.entries(descriptors)) {
|
|
18672
|
+
if (!descriptor2.enumerable) continue;
|
|
18673
|
+
if (Object.hasOwn(descriptor2, "value")) captured[field] = descriptor2.value;
|
|
18674
|
+
else accessors.push([field, descriptor2]);
|
|
18675
|
+
}
|
|
18676
|
+
return (allowAccessors = true) => {
|
|
18677
|
+
if (!allowAccessors && accessors.length > 0) fail("approved InventoryItems payload fields must be data properties; accessors are unsupported");
|
|
18678
|
+
const body = { ...captured };
|
|
18679
|
+
for (const [field, descriptor2] of accessors) {
|
|
18680
|
+
const capturedValue = descriptor2.get === void 0 ? void 0 : Reflect.apply(descriptor2.get, value, []);
|
|
18681
|
+
Object.defineProperty(body, field, { value: capturedValue, enumerable: true });
|
|
18682
|
+
}
|
|
18683
|
+
return body;
|
|
18684
|
+
};
|
|
18685
|
+
}
|
|
18686
|
+
function captureInventoryOptionDescriptors(options) {
|
|
18687
|
+
if (types.isProxy(options)) fail("options must not be a Proxy");
|
|
18688
|
+
if (!isRecord2(options)) fail("options must be an object");
|
|
18689
|
+
const prototype = Object.getPrototypeOf(options);
|
|
18690
|
+
for (let owner = prototype; owner !== null && owner !== Object.prototype; owner = Object.getPrototypeOf(owner)) {
|
|
18691
|
+
if (types.isProxy(owner)) fail("options must not inherit from a Proxy");
|
|
18692
|
+
}
|
|
18693
|
+
const descriptors = Object.getOwnPropertyDescriptors(options);
|
|
18694
|
+
const fact = Object.hasOwn(descriptors, "expectedInventoryFacts") ? descriptors.expectedInventoryFacts : void 0;
|
|
18695
|
+
if (fact === void 0 ? "expectedInventoryFacts" in options : !Object.hasOwn(fact, "value")) {
|
|
18696
|
+
fail("expectedInventoryFacts must be an own data property; accessors are unsupported");
|
|
18697
|
+
}
|
|
18698
|
+
const suppliedFacts = fact?.value;
|
|
18699
|
+
if (suppliedFacts !== void 0 && ![Object.prototype, null].includes(prototype)) fail("approved options must be a plain record");
|
|
18700
|
+
const expectedInventoryFacts = suppliedFacts === void 0 ? void 0 : snapshotExpectedInventoryFacts(suppliedFacts);
|
|
18701
|
+
return { options, descriptors, expectedInventoryFacts };
|
|
18702
|
+
}
|
|
18703
|
+
function snapshotInventoryMutationOptions(value) {
|
|
18704
|
+
const { options, descriptors, expectedInventoryFacts } = captureInventoryOptionDescriptors(value === void 0 ? {} : value);
|
|
18705
|
+
for (const key of MUTATION_OPTIONS) {
|
|
18706
|
+
if (key !== "expectedInventoryFacts" && !Object.hasOwn(descriptors, key) && key in options) fail(`${key} must be an own option`);
|
|
18707
|
+
}
|
|
18708
|
+
if (expectedInventoryFacts !== void 0 && Object.values(descriptors).some((descriptor2) => !Object.hasOwn(descriptor2, "value"))) fail("approved InventoryItems options must be data properties; accessors are unsupported");
|
|
18709
|
+
const captured = /* @__PURE__ */ Object.create(null);
|
|
18710
|
+
const dryRun = Object.hasOwn(descriptors, "dryRun") ? descriptors.dryRun : void 0;
|
|
18711
|
+
if (dryRun !== void 0) {
|
|
18712
|
+
const dataFlag = Object.hasOwn(dryRun, "value");
|
|
18713
|
+
const value2 = dataFlag ? dryRun.value : dryRun.get === void 0 ? void 0 : Reflect.apply(dryRun.get, options, []);
|
|
18714
|
+
captured.dryRun = !dataFlag && value2 === void 0 ? true : value2;
|
|
18715
|
+
}
|
|
18716
|
+
for (const key of MUTATION_OPTIONS) {
|
|
18717
|
+
if (key === "expectedInventoryFacts" || key === "dryRun") continue;
|
|
18718
|
+
const descriptor2 = descriptors[key];
|
|
18719
|
+
captured[key] = descriptor2 === void 0 ? void 0 : Object.hasOwn(descriptor2, "value") ? descriptor2.value : descriptor2.get === void 0 ? void 0 : Reflect.apply(descriptor2.get, options, []);
|
|
18720
|
+
}
|
|
18721
|
+
const result = snapshotMutationOptions(captured);
|
|
18722
|
+
if (expectedInventoryFacts !== void 0) result.expectedInventoryFacts = expectedInventoryFacts;
|
|
18723
|
+
if (result.lastModifiedDate !== void 0) fail("no documented stale timestamp is available");
|
|
18724
|
+
if (result.raw !== void 0 && result.raw !== false) fail("raw updates are unsupported");
|
|
18725
|
+
if (result.maxRetries !== void 0 && (!Number.isSafeInteger(result.maxRetries) || result.maxRetries < 0)) fail("maxRetries must be a nonnegative safe integer");
|
|
18726
|
+
if (result.verifyPersisted !== void 0 && typeof result.verifyPersisted !== "boolean") fail("verifyPersisted must be a boolean");
|
|
18727
|
+
return result;
|
|
18728
|
+
}
|
|
18729
|
+
function validateInventoryFactIntent(result, creating, data) {
|
|
18730
|
+
const facts = result.expectedInventoryFacts;
|
|
18731
|
+
if (facts === void 0) return;
|
|
18732
|
+
if (creating ? facts.item !== void 0 || facts.product === void 0 || facts.location === void 0 : facts.item === void 0 || facts.location !== void 0 || (Object.hasOwn(data, "quantityOnHand") ? facts.product === void 0 : facts.product !== void 0)) {
|
|
18733
|
+
fail("expectedInventoryFacts must supply only the facts required by this create or update");
|
|
18734
|
+
}
|
|
18735
|
+
if (creating && (facts.product.id !== data.productID || facts.location.id !== data.inventoryLocationID)) fail("expectedInventoryFacts references must match the submitted references");
|
|
18736
|
+
}
|
|
18737
|
+
function captureInventoryItemCall(value, options, creating) {
|
|
18738
|
+
const payload = captureInventoryPayload(value);
|
|
18739
|
+
const opts = snapshotInventoryMutationOptions(options);
|
|
18740
|
+
const body = admitInventoryItem(payload(opts.expectedInventoryFacts === void 0), creating);
|
|
18741
|
+
validateInventoryFactIntent(opts, creating, body);
|
|
18742
|
+
return { body, opts };
|
|
18743
|
+
}
|
|
18744
|
+
function deferredInventoryPayload(value, allowAccessors) {
|
|
18745
|
+
if (types.isProxy(value)) fail("payload must not be a Proxy");
|
|
18746
|
+
if (!isRecord2(value)) return value;
|
|
18747
|
+
if (![Object.prototype, null].includes(Object.getPrototypeOf(value))) fail("data must be a plain record");
|
|
18748
|
+
const result = Object.create(Object.getPrototypeOf(value));
|
|
18749
|
+
for (const [field, descriptor2] of Object.entries(Object.getOwnPropertyDescriptors(value))) {
|
|
18750
|
+
if (!descriptor2.enumerable) continue;
|
|
18751
|
+
if (Object.hasOwn(descriptor2, "value")) Object.defineProperty(result, field, { value: descriptor2.value, enumerable: true });
|
|
18752
|
+
else {
|
|
18753
|
+
if (!allowAccessors) fail("approved InventoryItems payload fields must be data properties; accessors are unsupported");
|
|
18754
|
+
let resolved = false;
|
|
18755
|
+
let captured;
|
|
18756
|
+
Object.defineProperty(result, field, { enumerable: true, get() {
|
|
18757
|
+
if (!resolved) {
|
|
18758
|
+
captured = descriptor2.get === void 0 ? void 0 : Reflect.apply(descriptor2.get, value, []);
|
|
18759
|
+
resolved = true;
|
|
18760
|
+
}
|
|
18761
|
+
return captured;
|
|
18762
|
+
} });
|
|
18763
|
+
}
|
|
18764
|
+
}
|
|
18765
|
+
return result;
|
|
18766
|
+
}
|
|
18767
|
+
function captureInventoryInvocationArgs(operation, args) {
|
|
18768
|
+
if (operation !== "inventory_items.create" && operation !== "inventory_items.update") return () => args;
|
|
18769
|
+
if (types.isProxy(args)) fail("invoke arguments must not be a Proxy");
|
|
18770
|
+
const array = Array.isArray(args);
|
|
18771
|
+
if (!array && (!isRecord2(args) || ![Object.prototype, null].includes(Object.getPrototypeOf(args))) || array && args.length !== (operation === "inventory_items.create" ? 1 : 2)) fail("InventoryItems invoke requires its documented positional or plain named inputs");
|
|
18772
|
+
const descriptors = Object.getOwnPropertyDescriptors(args);
|
|
18773
|
+
if (!array && Object.getOwnPropertySymbols(descriptors).length > 0) fail("InventoryItems named inputs must use string keys");
|
|
18774
|
+
const dataKey = array ? operation === "inventory_items.create" ? "0" : "1" : "data";
|
|
18775
|
+
const payload = descriptors[dataKey];
|
|
18776
|
+
const pinnedPayload = payload !== void 0 && Object.hasOwn(payload, "value") ? deferredInventoryPayload(payload.value, true) : void 0;
|
|
18777
|
+
return (allowAccessors = true) => {
|
|
18778
|
+
const result = array ? [] : Object.create(Object.getPrototypeOf(args));
|
|
18779
|
+
for (const [key, descriptor2] of Object.entries(descriptors)) {
|
|
18780
|
+
if (array && key === "length") continue;
|
|
18781
|
+
const enumerable = !array || descriptor2.enumerable;
|
|
18782
|
+
if (Object.hasOwn(descriptor2, "value")) {
|
|
18783
|
+
const value = key === dataKey ? deferredInventoryPayload(pinnedPayload, allowAccessors) : descriptor2.value;
|
|
18784
|
+
Object.defineProperty(result, key, { value, enumerable, configurable: true });
|
|
18785
|
+
} else {
|
|
18786
|
+
if (!allowAccessors) fail("approved InventoryItems named inputs must be data properties; accessors are unsupported");
|
|
18787
|
+
let resolved = false;
|
|
18788
|
+
let captured;
|
|
18789
|
+
Object.defineProperty(result, key, { enumerable, configurable: true, get() {
|
|
18790
|
+
if (!resolved) {
|
|
18791
|
+
const value = descriptor2.get === void 0 ? void 0 : Reflect.apply(descriptor2.get, args, []);
|
|
18792
|
+
captured = key === dataKey ? deferredInventoryPayload(value, true) : value;
|
|
18793
|
+
resolved = true;
|
|
18794
|
+
}
|
|
18795
|
+
return captured;
|
|
18796
|
+
} });
|
|
18797
|
+
}
|
|
18798
|
+
}
|
|
18799
|
+
return result;
|
|
18800
|
+
};
|
|
18801
|
+
}
|
|
18802
|
+
var ITEM_NUMERIC_FACTS = [...REFERENCES, ...QUANTITIES, "quantityPicked", "quantityReserved", "quantityOnOrder", "backOrderQuantity", "impersonatorCreatorResourceID"];
|
|
18803
|
+
var ITEM_FACT_KEYS = ["id", ...ITEM_NUMERIC_FACTS, ...TEXT_FIELDS];
|
|
18804
|
+
function inventoryItemGuardFacts(value) {
|
|
18805
|
+
const captured = closedFacts(value, ITEM_FACT_KEYS, false);
|
|
18806
|
+
if (!Object.hasOwn(captured, "id")) fail("inventory facts require an own item id");
|
|
18807
|
+
const facts = { id: inventoryItemId(captured.id) };
|
|
18808
|
+
for (const field of ITEM_NUMERIC_FACTS) if (Object.hasOwn(captured, field)) {
|
|
18809
|
+
const current = captured[field];
|
|
18810
|
+
facts[field] = current === null ? null : int32(current, "inventory fact");
|
|
18811
|
+
}
|
|
18812
|
+
for (const field of TEXT_FIELDS) if (Object.hasOwn(captured, field)) {
|
|
18813
|
+
const current = captured[field];
|
|
18814
|
+
if (current !== null && typeof current !== "string") fail("inventory text facts must be strings or null");
|
|
18815
|
+
facts[field] = current;
|
|
18816
|
+
}
|
|
18817
|
+
return facts;
|
|
18818
|
+
}
|
|
18819
|
+
function closedFacts(value, fields, closed = true) {
|
|
18820
|
+
if (types.isProxy(value)) fail("expectedInventoryFacts records must not be a Proxy");
|
|
18821
|
+
if (!isRecord2(value) || ![Object.prototype, null].includes(Object.getPrototypeOf(value))) fail("expectedInventoryFacts must contain plain records");
|
|
18822
|
+
const descriptors = Object.getOwnPropertyDescriptors(value);
|
|
18823
|
+
if (closed && Reflect.ownKeys(descriptors).some((key) => typeof key !== "string" || !fields.includes(key))) fail("expectedInventoryFacts contains an unsupported field");
|
|
18824
|
+
for (const key of fields) if (key in value && !Object.hasOwn(value, key)) fail("expectedInventoryFacts fields must be own fields");
|
|
18825
|
+
const captured = /* @__PURE__ */ Object.create(null);
|
|
18826
|
+
for (const key of fields) {
|
|
18827
|
+
const descriptor2 = descriptors[key];
|
|
18828
|
+
if (descriptor2 === void 0) continue;
|
|
18829
|
+
if (!Object.hasOwn(descriptor2, "value")) fail("expectedInventoryFacts fields must be data properties; accessors are unsupported");
|
|
18830
|
+
captured[key] = descriptor2.value;
|
|
18831
|
+
}
|
|
18832
|
+
return captured;
|
|
18833
|
+
}
|
|
18834
|
+
function snapshotExpectedInventoryFacts(value) {
|
|
18835
|
+
const source = closedFacts(value, ["item", "product", "location"]);
|
|
18836
|
+
const result = {};
|
|
18837
|
+
if (Object.hasOwn(source, "item")) {
|
|
18838
|
+
const item = closedFacts(source.item, ITEM_FACT_KEYS);
|
|
18839
|
+
result.item = inventoryItemGuardFacts(item);
|
|
18840
|
+
}
|
|
18841
|
+
for (const kind of ["product", "location"]) if (Object.hasOwn(source, kind)) {
|
|
18842
|
+
const flag = kind === "product" ? "isSerialized" : "isActive";
|
|
18843
|
+
const record = closedFacts(source[kind], ["id", flag]);
|
|
18844
|
+
const id = int32(own(record, "id"), "expected reference id", 1);
|
|
18845
|
+
const state2 = own(record, flag);
|
|
18846
|
+
if (typeof state2 !== "boolean") fail("expected reference state must be an own boolean");
|
|
18847
|
+
if (kind === "product") result.product = { id, isSerialized: state2 };
|
|
18848
|
+
else result.location = { id, isActive: state2 };
|
|
18849
|
+
}
|
|
18850
|
+
return result;
|
|
18851
|
+
}
|
|
18852
|
+
function rejectInventoryFactsOption(options, operation) {
|
|
18853
|
+
if (operation === "inventory_items.create" || operation === "inventory_items.update" || !isRecord2(options)) return;
|
|
18854
|
+
const option = Object.getOwnPropertyDescriptor(options, "expectedInventoryFacts");
|
|
18855
|
+
if (option === void 0 && !("expectedInventoryFacts" in options)) return;
|
|
18856
|
+
if (option !== void 0 && Object.hasOwn(option, "value") && option.value === void 0) return;
|
|
18857
|
+
fail("expectedInventoryFacts is supported only by inventory_items.create/update");
|
|
18858
|
+
}
|
|
18859
|
+
function inventoryFactsStale(operation) {
|
|
18860
|
+
const error = new StaleObjectError("inventory_items: approved facts changed; no mutation was sent", {
|
|
18861
|
+
operation,
|
|
18862
|
+
suggestedAction: "Read fresh inventory facts and generate a new preview and approval before retrying."
|
|
18863
|
+
});
|
|
18864
|
+
Object.assign(error, { notSent: true });
|
|
18865
|
+
throw error;
|
|
18866
|
+
}
|
|
18867
|
+
function rethrowInventoryGuardError(error, expected, operation) {
|
|
18868
|
+
if (expected !== void 0 && error instanceof NotFoundError && error.httpStatus === 200) inventoryFactsStale(operation);
|
|
18869
|
+
throw error;
|
|
18870
|
+
}
|
|
18871
|
+
function assertApprovedFacts(expected, actual, operation) {
|
|
18872
|
+
const before = expected;
|
|
18873
|
+
const after = actual;
|
|
18874
|
+
if (Object.keys(before).length !== Object.keys(after).length || Object.keys(before).some((key) => !Object.hasOwn(after, key) || before[key] !== after[key])) {
|
|
18875
|
+
inventoryFactsStale(operation);
|
|
18876
|
+
}
|
|
18877
|
+
}
|
|
18878
|
+
function assertQuantityRange(minimum, maximum) {
|
|
18879
|
+
if (typeof minimum === "number" && typeof maximum === "number" && maximum < minimum) fail("quantityMaximum must be at least quantityMinimum");
|
|
18880
|
+
}
|
|
18881
|
+
function exactItem(value, id, label, approvedOperation) {
|
|
18882
|
+
const record = isRecord2(value);
|
|
18883
|
+
if (approvedOperation !== void 0 && (!record || own(value, "id") === null)) {
|
|
18884
|
+
throw Object.assign(new AutotaskError("InventoryItems approval could not verify the Product item or its exact ID", {
|
|
18885
|
+
code: "INVALID_RESPONSE",
|
|
18886
|
+
category: "server",
|
|
18887
|
+
operation: approvedOperation
|
|
18888
|
+
}), { notSent: true });
|
|
18889
|
+
}
|
|
18890
|
+
if (!record) fail(`${label} must be a record`);
|
|
18891
|
+
if (approvedOperation !== void 0 && !Object.hasOwn(value, "id")) inventoryFactsStale(approvedOperation);
|
|
18892
|
+
const returned = own(value, "id");
|
|
18893
|
+
if (typeof returned !== "string" && (typeof returned !== "number" || !Number.isSafeInteger(returned))) fail(`${label} requires its own exact id`);
|
|
18894
|
+
if (String(returned) !== String(id)) {
|
|
18895
|
+
if (approvedOperation !== void 0 && isAuditDecimalId(String(returned))) inventoryFactsStale(approvedOperation);
|
|
18896
|
+
fail(`${label} id must match the requested id`);
|
|
18897
|
+
}
|
|
18898
|
+
return value;
|
|
18899
|
+
}
|
|
18900
|
+
async function productIsSerialized(http, id, checkedBaseUrl, maxRetries, expected, mutationOperation = "inventory_items.update") {
|
|
18901
|
+
const operation = "products.get";
|
|
18902
|
+
const body = await http.request({
|
|
18903
|
+
method: "GET",
|
|
18904
|
+
path: `/V1.0/Products/${id}`,
|
|
18905
|
+
operation,
|
|
18906
|
+
maxRetries,
|
|
18907
|
+
checkedBaseUrl,
|
|
18908
|
+
...expected !== void 0 ? { [INVENTORY_APPROVAL_PRODUCT_ID]: true } : {}
|
|
18909
|
+
});
|
|
18910
|
+
let raw;
|
|
18911
|
+
try {
|
|
18912
|
+
raw = unwrapItem(body, id, operation, "product");
|
|
18913
|
+
} catch (error) {
|
|
18914
|
+
rethrowInventoryGuardError(error, expected === void 0 ? void 0 : { }, mutationOperation);
|
|
18915
|
+
}
|
|
18916
|
+
const product = exactItem(raw, id, "product", expected === void 0 ? void 0 : mutationOperation);
|
|
18917
|
+
const serialized = own(product, "isSerialized");
|
|
18918
|
+
if (expected !== void 0) assertApprovedFacts(expected, { id, isSerialized: serialized }, mutationOperation);
|
|
18919
|
+
if (typeof serialized !== "boolean") fail("product requires a fresh boolean isSerialized fact");
|
|
18920
|
+
return serialized;
|
|
18921
|
+
}
|
|
18922
|
+
async function guardInventoryItemCreate(http, data, checkedBaseUrl, maxRetries, expected) {
|
|
18923
|
+
const locationId = data.inventoryLocationID;
|
|
18924
|
+
const operation = "inventory_locations.get";
|
|
18925
|
+
const body = await http.request({ method: "GET", path: `/V1.0/InventoryLocations/${locationId}`, operation, maxRetries, checkedBaseUrl });
|
|
18926
|
+
let raw;
|
|
18927
|
+
try {
|
|
18928
|
+
raw = unwrapItem(body, locationId, operation, "inventory_location");
|
|
18929
|
+
} catch (error) {
|
|
18930
|
+
rethrowInventoryGuardError(error, expected, "inventory_items.create");
|
|
18931
|
+
}
|
|
18932
|
+
const location = exactItem(raw, locationId, "inventory location");
|
|
18933
|
+
if (expected?.location !== void 0) assertApprovedFacts(expected.location, { id: locationId, isActive: own(location, "isActive") }, "inventory_items.create");
|
|
18934
|
+
if (own(location, "isActive") !== true) fail("inventory location requires a fresh isActive value explicitly true");
|
|
18935
|
+
if (await productIsSerialized(http, data.productID, checkedBaseUrl, maxRetries, expected?.product, "inventory_items.create") && data.quantityOnHand !== 0) {
|
|
18936
|
+
fail("quantityOnHand must be zero when creating an item for a serialized product");
|
|
18937
|
+
}
|
|
18938
|
+
}
|
|
18939
|
+
async function checkInventoryItemCurrent(http, data, current, id, checkedBaseUrl, maxRetries, expected) {
|
|
18940
|
+
const item = exactItem(current, id, "current record");
|
|
18941
|
+
if (expected?.item !== void 0) assertApprovedFacts(expected.item, inventoryItemGuardFacts(item), "inventory_items.update");
|
|
18942
|
+
const minimum = own(data, "quantityMinimum");
|
|
18943
|
+
const maximum = own(data, "quantityMaximum");
|
|
18944
|
+
if (minimum !== void 0 || maximum !== void 0) {
|
|
18945
|
+
assertQuantityRange(
|
|
18946
|
+
minimum ?? int32(own(item, "quantityMinimum"), "current quantityMinimum", 0),
|
|
18947
|
+
maximum ?? int32(own(item, "quantityMaximum"), "current quantityMaximum")
|
|
18948
|
+
);
|
|
18949
|
+
}
|
|
18950
|
+
const onHand = own(data, "quantityOnHand");
|
|
18951
|
+
if (typeof onHand !== "number") return;
|
|
18952
|
+
const picked = int32(own(item, "quantityPicked"), "current quantityPicked");
|
|
18953
|
+
const reserved = int32(own(item, "quantityReserved"), "current quantityReserved");
|
|
18954
|
+
if (onHand < picked + reserved) fail("quantityOnHand must be at least quantityPicked plus quantityReserved");
|
|
18955
|
+
const productId = int32(own(item, "productID"), "current productID", 1);
|
|
18956
|
+
if (await productIsSerialized(http, productId, checkedBaseUrl, maxRetries, expected?.product)) fail("quantityOnHand is read-only on update for a serialized product");
|
|
18957
|
+
}
|
|
18958
|
+
|
|
18460
18959
|
// src/operations/requiredFields.ts
|
|
18461
18960
|
function effectiveRequiredFields(record, zoneFacts) {
|
|
18462
18961
|
const guidance = zoneFacts?.createGuidance;
|
|
@@ -19060,166 +19559,6 @@ async function fieldCatalog(client, opts) {
|
|
|
19060
19559
|
return result;
|
|
19061
19560
|
}
|
|
19062
19561
|
|
|
19063
|
-
// src/resources/base/helpers.ts
|
|
19064
|
-
function describeResponseShape(body) {
|
|
19065
|
-
if (body === null) return "null";
|
|
19066
|
-
if (Array.isArray(body)) return `array(len=${body.length})`;
|
|
19067
|
-
if (typeof body !== "object") return typeof body;
|
|
19068
|
-
const rec = body;
|
|
19069
|
-
const keys = Object.keys(rec).sort();
|
|
19070
|
-
const typeOf = (v) => v === null ? "null" : Array.isArray(v) ? "array" : typeof v;
|
|
19071
|
-
const parts = keys.slice(0, 16).map((k) => `${k}:${typeOf(rec[k])}`);
|
|
19072
|
-
const more = keys.length > 16 ? `, +${keys.length - 16} more` : "";
|
|
19073
|
-
return `{ ${parts.join(", ")}${more} }`;
|
|
19074
|
-
}
|
|
19075
|
-
function defaultMarkerToken(data) {
|
|
19076
|
-
for (const field of ["name", "title"]) {
|
|
19077
|
-
const v = data[field];
|
|
19078
|
-
if (typeof v === "string" && v.trim() !== "") return v.trim();
|
|
19079
|
-
}
|
|
19080
|
-
return null;
|
|
19081
|
-
}
|
|
19082
|
-
var CONTEXT_ABSENT_MARKER = "#context-absent";
|
|
19083
|
-
function contextAbsentKey(path) {
|
|
19084
|
-
return path + "\0context-absent";
|
|
19085
|
-
}
|
|
19086
|
-
function noteCharsTruncationMarker(charsRemoved) {
|
|
19087
|
-
return `\u2026 [+${charsRemoved} chars truncated]`;
|
|
19088
|
-
}
|
|
19089
|
-
function truncateNoteChars(items, cap, fields) {
|
|
19090
|
-
let truncated = 0;
|
|
19091
|
-
const out = items.map((item) => {
|
|
19092
|
-
if (!isRecord2(item)) return item;
|
|
19093
|
-
let changed = false;
|
|
19094
|
-
const copy = { ...item };
|
|
19095
|
-
for (const field of fields) {
|
|
19096
|
-
const v = copy[field];
|
|
19097
|
-
if (typeof v === "string" && v !== REDACTED && v.length > cap) {
|
|
19098
|
-
const end = cap > 0 && (v.charCodeAt(cap - 1) & 64512) === 55296 ? cap - 1 : cap;
|
|
19099
|
-
copy[field] = v.slice(0, end) + noteCharsTruncationMarker(v.length - end);
|
|
19100
|
-
truncated += 1;
|
|
19101
|
-
changed = true;
|
|
19102
|
-
}
|
|
19103
|
-
}
|
|
19104
|
-
return changed ? copy : item;
|
|
19105
|
-
});
|
|
19106
|
-
return [out, truncated];
|
|
19107
|
-
}
|
|
19108
|
-
function blindEmptyReason(stamp) {
|
|
19109
|
-
return {
|
|
19110
|
-
surface: stamp.surface,
|
|
19111
|
-
kind: "blind-surface",
|
|
19112
|
-
note: stamp.note,
|
|
19113
|
-
authority: stamp.authority,
|
|
19114
|
-
remedy: "the note is the remedy \u2014 the authority op answers for a record"
|
|
19115
|
-
};
|
|
19116
|
-
}
|
|
19117
|
-
function attachUpdateTargetMissReason(err, key) {
|
|
19118
|
-
const pinned = EMPTY_REASON_STAMPS[key]?.update;
|
|
19119
|
-
if (pinned === void 0) return;
|
|
19120
|
-
err.details = { ...err.details ?? {}, emptyReason: pinned };
|
|
19121
|
-
}
|
|
19122
|
-
function buildDryRunResult(spec, policy) {
|
|
19123
|
-
if (spec.operation === "") {
|
|
19124
|
-
throw new AutotaskConfigError("dry-run: the operation name is required");
|
|
19125
|
-
}
|
|
19126
|
-
const wouldApply = spec.checks.every((check) => check.ok);
|
|
19127
|
-
const resource = spec.operation.split(".")[0] ?? spec.operation;
|
|
19128
|
-
const diffPart = spec.diff !== void 0 ? {
|
|
19129
|
-
diff: spec.diff.map((entry) => {
|
|
19130
|
-
if (entry.to === void 0) return entry;
|
|
19131
|
-
const to = isRedactedFieldName(entry.field, policy) ? REDACTED : redactResponseBody(entry.to, policy);
|
|
19132
|
-
return { ...entry, to };
|
|
19133
|
-
})
|
|
19134
|
-
} : {};
|
|
19135
|
-
const dataPart = spec.data !== void 0 ? { data: redactResponseBody(spec.data, policy) } : {};
|
|
19136
|
-
return {
|
|
19137
|
-
operation: spec.operation,
|
|
19138
|
-
wouldApply,
|
|
19139
|
-
target: { resource, ids: spec.ids },
|
|
19140
|
-
request: { method: spec.method, path: spec.path },
|
|
19141
|
-
...diffPart,
|
|
19142
|
-
checks: spec.checks,
|
|
19143
|
-
impact: spec.impact,
|
|
19144
|
-
simulated: true,
|
|
19145
|
-
warnings: spec.warnings ?? [],
|
|
19146
|
-
...dataPart,
|
|
19147
|
-
...spec.emptyReason !== void 0 ? { emptyReason: spec.emptyReason } : {}
|
|
19148
|
-
};
|
|
19149
|
-
}
|
|
19150
|
-
function computeFieldDiff(current, data) {
|
|
19151
|
-
const out = [];
|
|
19152
|
-
for (const [field, to] of Object.entries(data)) {
|
|
19153
|
-
if (field === "id" || to === void 0) continue;
|
|
19154
|
-
const from = Object.hasOwn(current, field) ? current[field] : void 0;
|
|
19155
|
-
if (from !== void 0 && JSON.stringify(from) === JSON.stringify(to)) continue;
|
|
19156
|
-
out.push({ field, from: from === void 0 ? null : from, to });
|
|
19157
|
-
}
|
|
19158
|
-
return out;
|
|
19159
|
-
}
|
|
19160
|
-
function mergePartialBody(current, data) {
|
|
19161
|
-
const merged = { ...current };
|
|
19162
|
-
for (const [key, value] of Object.entries(data)) {
|
|
19163
|
-
if (value === void 0) continue;
|
|
19164
|
-
merged[key] = value;
|
|
19165
|
-
}
|
|
19166
|
-
return merged;
|
|
19167
|
-
}
|
|
19168
|
-
function snapshotMutationOptions(options) {
|
|
19169
|
-
const { dryRun, lastModifiedDate, maxRetries, raw, verifyPersisted } = options ?? {};
|
|
19170
|
-
if (dryRun !== void 0 && typeof dryRun !== "boolean") {
|
|
19171
|
-
throw new AutotaskConfigError("dryRun must be a boolean");
|
|
19172
|
-
}
|
|
19173
|
-
return { dryRun, lastModifiedDate, maxRetries, raw, verifyPersisted };
|
|
19174
|
-
}
|
|
19175
|
-
function normalizeUdfInput(value) {
|
|
19176
|
-
if (Array.isArray(value)) {
|
|
19177
|
-
return value.map((entry) => {
|
|
19178
|
-
if (!isRecord2(entry) || typeof entry.name !== "string" || entry.name === "") {
|
|
19179
|
-
throw new AutotaskConfigError("userDefinedFields array entries must be { name, value } objects");
|
|
19180
|
-
}
|
|
19181
|
-
return { name: entry.name, value: entry.value };
|
|
19182
|
-
});
|
|
19183
|
-
}
|
|
19184
|
-
if (isRecord2(value)) {
|
|
19185
|
-
return Object.entries(value).map(([name, entryValue]) => ({ name, value: entryValue }));
|
|
19186
|
-
}
|
|
19187
|
-
throw new AutotaskConfigError("userDefinedFields must be an array of { name, value } entries or a name-to-value map");
|
|
19188
|
-
}
|
|
19189
|
-
function blindStampFor(stamp, filter) {
|
|
19190
|
-
if (stamp === void 0) return void 0;
|
|
19191
|
-
if (stamp.kind !== "unfiltered-blind") return stamp;
|
|
19192
|
-
const conditions = normalizedConditions(filter);
|
|
19193
|
-
return conditions === void 0 || conditions.length === 0 ? stamp : void 0;
|
|
19194
|
-
}
|
|
19195
|
-
function decodeFileData(body) {
|
|
19196
|
-
if (isRecord2(body)) {
|
|
19197
|
-
const data = body.data;
|
|
19198
|
-
if (typeof data === "string") return Buffer.from(data, "base64");
|
|
19199
|
-
if (Array.isArray(data) && data.every((b) => typeof b === "number")) {
|
|
19200
|
-
return Buffer.from(data);
|
|
19201
|
-
}
|
|
19202
|
-
}
|
|
19203
|
-
if (typeof body === "string") return Buffer.from(body, "base64");
|
|
19204
|
-
throw new AutotaskError(
|
|
19205
|
-
"Expected the file envelope FileQueryResultModel { data } (or a base64 string); got a different shape",
|
|
19206
|
-
{ code: "INVALID_RESPONSE", category: "server" }
|
|
19207
|
-
);
|
|
19208
|
-
}
|
|
19209
|
-
var DEPLURAL_EXCEPTIONS = {
|
|
19210
|
-
tag_aliase: "tag_alias"
|
|
19211
|
-
};
|
|
19212
|
-
function entityNameFromPath(resourcePath) {
|
|
19213
|
-
const segment = resourcePath.slice(resourcePath.lastIndexOf("/") + 1);
|
|
19214
|
-
const snake = segment.replace(/([A-Z])/g, (_m, c, i) => (i > 0 ? `_` : "") + c.toLowerCase()).replace(/_{2,}/g, "_");
|
|
19215
|
-
if (snake.endsWith("ies")) return `${snake.slice(0, -3)}y`;
|
|
19216
|
-
if (snake.endsWith("s")) {
|
|
19217
|
-
const stripped = snake.slice(0, -1);
|
|
19218
|
-
return DEPLURAL_EXCEPTIONS[stripped] ?? stripped;
|
|
19219
|
-
}
|
|
19220
|
-
return snake;
|
|
19221
|
-
}
|
|
19222
|
-
|
|
19223
19562
|
// src/operations/nameSnapshot.ts
|
|
19224
19563
|
function nameRecordSnapshot(cache, path, id, operation) {
|
|
19225
19564
|
const body = cache?.get(path);
|
|
@@ -20064,17 +20403,17 @@ function validateParamsBag(record, args) {
|
|
|
20064
20403
|
}
|
|
20065
20404
|
);
|
|
20066
20405
|
}
|
|
20067
|
-
var INVOKE_OPTION_KEYS = ["dryRun", "confirm", "lastModifiedDate", "maxRetries", "fresh", "verifyPersisted", "mode"];
|
|
20406
|
+
var INVOKE_OPTION_KEYS = ["dryRun", "confirm", "lastModifiedDate", "maxRetries", "fresh", "verifyPersisted", "expectedInventoryFacts", "mode"];
|
|
20068
20407
|
function validateInvokeOptions(opts, operation) {
|
|
20069
20408
|
if (opts === void 0 || opts === null) return;
|
|
20070
20409
|
const unknown = Object.keys(opts).filter((k) => !INVOKE_OPTION_KEYS.includes(k));
|
|
20071
20410
|
if (unknown.length === 0) return;
|
|
20072
|
-
const suggestions = keySuggestions(unknown, ["dryRun", "confirm", "lastModifiedDate", "maxRetries", "fresh", "verifyPersisted"]);
|
|
20411
|
+
const suggestions = keySuggestions(unknown, ["dryRun", "confirm", "lastModifiedDate", "maxRetries", "fresh", "verifyPersisted", "expectedInventoryFacts"]);
|
|
20073
20412
|
throw new AutotaskConfigError(
|
|
20074
|
-
`invoke: "${operation}" has unknown option key(s) ${unknown.map((k) => `"${k}"`).join(", ")} \u2014 the options set is closed (valid: dryRun, confirm, lastModifiedDate, maxRetries, fresh, verifyPersisted; "mode" is internal to the mode wrappers)`,
|
|
20413
|
+
`invoke: "${operation}" has unknown option key(s) ${unknown.map((k) => `"${k}"`).join(", ")} \u2014 the options set is closed (valid: dryRun, confirm, lastModifiedDate, maxRetries, fresh, verifyPersisted, expectedInventoryFacts; "mode" is internal to the mode wrappers)`,
|
|
20075
20414
|
{
|
|
20076
20415
|
operation,
|
|
20077
|
-
suggestedAction: suggestions.length > 0 ? `Fix the option name (${suggestions.join(", ")}).` : `Pass only dryRun / confirm / lastModifiedDate / maxRetries / fresh / verifyPersisted.`
|
|
20416
|
+
suggestedAction: suggestions.length > 0 ? `Fix the option name (${suggestions.join(", ")}).` : `Pass only dryRun / confirm / lastModifiedDate / maxRetries / fresh / verifyPersisted / expectedInventoryFacts.`
|
|
20078
20417
|
}
|
|
20079
20418
|
);
|
|
20080
20419
|
}
|
|
@@ -20093,126 +20432,24 @@ function unknownKeysRefusal(raw, validKeys, subject, operation) {
|
|
|
20093
20432
|
}
|
|
20094
20433
|
|
|
20095
20434
|
// src/resources/special/inventoryLocations.ts
|
|
20096
|
-
var
|
|
20435
|
+
var fail2 = (message) => {
|
|
20097
20436
|
throw new AutotaskConfigError(`inventory_locations: ${message}`);
|
|
20098
20437
|
};
|
|
20099
20438
|
function admitInventoryLocation(value, creating) {
|
|
20100
|
-
if (!isRecord2(value) || ![Object.prototype, null].includes(Object.getPrototypeOf(value)))
|
|
20439
|
+
if (!isRecord2(value) || ![Object.prototype, null].includes(Object.getPrototypeOf(value))) fail2("data must be a plain record");
|
|
20101
20440
|
const body = { ...value };
|
|
20102
|
-
for (const field of Object.keys(body)) if (!["locationName", "isActive"].includes(field))
|
|
20441
|
+
for (const field of Object.keys(body)) if (!["locationName", "isActive"].includes(field)) fail2(`${field} is not a writable InventoryLocations field`);
|
|
20103
20442
|
const hasName = Object.hasOwn(body, "locationName");
|
|
20104
20443
|
const hasActive = Object.hasOwn(body, "isActive");
|
|
20105
|
-
if (creating && !hasName || hasName && (typeof body.locationName !== "string" || body.locationName.trim() === "" || body.locationName.length > 50))
|
|
20106
|
-
if (creating && !hasActive || hasActive && typeof body.isActive !== "boolean")
|
|
20107
|
-
if (!creating && !hasName && !hasActive)
|
|
20444
|
+
if (creating && !hasName || hasName && (typeof body.locationName !== "string" || body.locationName.trim() === "" || body.locationName.length > 50)) fail2("locationName is required and must be a nonblank string of at most 50 characters");
|
|
20445
|
+
if (creating && !hasActive || hasActive && typeof body.isActive !== "boolean") fail2("isActive must be a boolean");
|
|
20446
|
+
if (!creating && !hasName && !hasActive) fail2("update must contain locationName or isActive");
|
|
20108
20447
|
return body;
|
|
20109
20448
|
}
|
|
20110
20449
|
function checkInventoryLocationCurrent(value, current, id) {
|
|
20111
|
-
if (!isRecord2(current) || !Object.hasOwn(current, "id"))
|
|
20112
|
-
if (parseIdentifier(current.id, "inventory_locations: current id") !== id)
|
|
20113
|
-
if (Object.hasOwn(value, "isActive") && value.isActive === false && (!Object.hasOwn(current, "isDefault") || current.isDefault !== false))
|
|
20114
|
-
}
|
|
20115
|
-
|
|
20116
|
-
// src/resources/special/inventoryItems.ts
|
|
20117
|
-
var REFERENCES = ["inventoryLocationID", "productID"];
|
|
20118
|
-
var QUANTITIES = ["quantityMinimum", "quantityMaximum", "quantityOnHand"];
|
|
20119
|
-
var TEXT_FIELDS = ["bin", "referenceNumber"];
|
|
20120
|
-
var MUTATION_OPTIONS = ["dryRun", "lastModifiedDate", "maxRetries", "raw", "verifyPersisted"];
|
|
20121
|
-
function fail2(message) {
|
|
20122
|
-
throw new AutotaskConfigError(`inventory_items: ${message}`);
|
|
20123
|
-
}
|
|
20124
|
-
function own(record, field) {
|
|
20125
|
-
return Object.hasOwn(record, field) ? record[field] : void 0;
|
|
20126
|
-
}
|
|
20127
|
-
function int32(value, label, minimum = -2147483648) {
|
|
20128
|
-
if (typeof value !== "number" || !Number.isInteger(value) || value < minimum || value > 2147483647) {
|
|
20129
|
-
fail2(`${label} must be an integer between ${minimum} and 2147483647`);
|
|
20130
|
-
}
|
|
20131
|
-
return value;
|
|
20132
|
-
}
|
|
20133
|
-
function inventoryItemId(value) {
|
|
20134
|
-
const id = parseIdentifier(value, "inventory_items: id");
|
|
20135
|
-
if (!isAuditDecimalId(String(id))) fail2("id must fit a signed 64-bit integer");
|
|
20136
|
-
return id;
|
|
20137
|
-
}
|
|
20138
|
-
function admitInventoryItem(value, creating) {
|
|
20139
|
-
if (!isRecord2(value) || ![Object.prototype, null].includes(Object.getPrototypeOf(value))) fail2("data must be a plain record");
|
|
20140
|
-
const body = { ...value };
|
|
20141
|
-
const writable = [...QUANTITIES, ...TEXT_FIELDS, ...creating ? REFERENCES : []];
|
|
20142
|
-
for (const field of Object.keys(body)) {
|
|
20143
|
-
if (!writable.some((name) => name === field)) fail2(`${field} is not a writable InventoryItems field on ${creating ? "create" : "update"}`);
|
|
20144
|
-
}
|
|
20145
|
-
if (!creating && Object.keys(body).length === 0) fail2("update must contain a writable field");
|
|
20146
|
-
if (creating) for (const field of REFERENCES) int32(own(body, field), field, 1);
|
|
20147
|
-
for (const field of QUANTITIES) {
|
|
20148
|
-
const nonnegative = field === "quantityMinimum" || creating && field === "quantityOnHand";
|
|
20149
|
-
if (creating || Object.hasOwn(body, field)) int32(own(body, field), field, nonnegative ? 0 : void 0);
|
|
20150
|
-
}
|
|
20151
|
-
for (const field of TEXT_FIELDS) {
|
|
20152
|
-
const text = own(body, field);
|
|
20153
|
-
if (Object.hasOwn(body, field) && (typeof text !== "string" || text.length > 50)) fail2(`${field} must be a string of at most 50 characters`);
|
|
20154
|
-
}
|
|
20155
|
-
assertQuantityRange(own(body, "quantityMinimum"), own(body, "quantityMaximum"));
|
|
20156
|
-
return body;
|
|
20157
|
-
}
|
|
20158
|
-
function snapshotInventoryItemOptions(value) {
|
|
20159
|
-
if (value !== void 0 && !isRecord2(value)) fail2("options must be an object");
|
|
20160
|
-
const options = value ?? {};
|
|
20161
|
-
for (const key of MUTATION_OPTIONS) {
|
|
20162
|
-
if (key in options && !Object.hasOwn(options, key)) fail2(`${key} must be an own option`);
|
|
20163
|
-
}
|
|
20164
|
-
const result = snapshotMutationOptions(Object.fromEntries(MUTATION_OPTIONS.map((key) => [key, own(options, key)])));
|
|
20165
|
-
if (result.lastModifiedDate !== void 0) fail2("no documented stale timestamp is available");
|
|
20166
|
-
if (result.raw !== void 0 && result.raw !== false) fail2("raw updates are unsupported");
|
|
20167
|
-
if (result.maxRetries !== void 0 && (!Number.isSafeInteger(result.maxRetries) || result.maxRetries < 0)) fail2("maxRetries must be a nonnegative safe integer");
|
|
20168
|
-
if (result.verifyPersisted !== void 0 && typeof result.verifyPersisted !== "boolean") fail2("verifyPersisted must be a boolean");
|
|
20169
|
-
return result;
|
|
20170
|
-
}
|
|
20171
|
-
function assertQuantityRange(minimum, maximum) {
|
|
20172
|
-
if (typeof minimum === "number" && typeof maximum === "number" && maximum < minimum) fail2("quantityMaximum must be at least quantityMinimum");
|
|
20173
|
-
}
|
|
20174
|
-
function exactItem(value, id, label) {
|
|
20175
|
-
if (!isRecord2(value)) fail2(`${label} must be a record`);
|
|
20176
|
-
const returned = own(value, "id");
|
|
20177
|
-
if (typeof returned !== "string" && (typeof returned !== "number" || !Number.isSafeInteger(returned))) fail2(`${label} requires its own exact id`);
|
|
20178
|
-
if (String(returned) !== String(id)) fail2(`${label} id must match the requested id`);
|
|
20179
|
-
return value;
|
|
20180
|
-
}
|
|
20181
|
-
async function productIsSerialized(http, id, checkedBaseUrl, maxRetries) {
|
|
20182
|
-
const operation = "products.get";
|
|
20183
|
-
const body = await http.request({ method: "GET", path: `/V1.0/Products/${id}`, operation, maxRetries, checkedBaseUrl });
|
|
20184
|
-
const product = exactItem(unwrapItem(body, id, operation, "product"), id, "product");
|
|
20185
|
-
const serialized = own(product, "isSerialized");
|
|
20186
|
-
if (typeof serialized !== "boolean") fail2("product requires a fresh boolean isSerialized fact");
|
|
20187
|
-
return serialized;
|
|
20188
|
-
}
|
|
20189
|
-
async function guardInventoryItemCreate(http, data, checkedBaseUrl, maxRetries) {
|
|
20190
|
-
const locationId = data.inventoryLocationID;
|
|
20191
|
-
const operation = "inventory_locations.get";
|
|
20192
|
-
const body = await http.request({ method: "GET", path: `/V1.0/InventoryLocations/${locationId}`, operation, maxRetries, checkedBaseUrl });
|
|
20193
|
-
const location = exactItem(unwrapItem(body, locationId, operation, "inventory_location"), locationId, "inventory location");
|
|
20194
|
-
if (own(location, "isActive") !== true) fail2("inventory location requires a fresh isActive value explicitly true");
|
|
20195
|
-
if (await productIsSerialized(http, data.productID, checkedBaseUrl, maxRetries) && data.quantityOnHand !== 0) {
|
|
20196
|
-
fail2("quantityOnHand must be zero when creating an item for a serialized product");
|
|
20197
|
-
}
|
|
20198
|
-
}
|
|
20199
|
-
async function checkInventoryItemCurrent(http, data, current, id, checkedBaseUrl, maxRetries) {
|
|
20200
|
-
const item = exactItem(current, id, "current record");
|
|
20201
|
-
const minimum = own(data, "quantityMinimum");
|
|
20202
|
-
const maximum = own(data, "quantityMaximum");
|
|
20203
|
-
if (minimum !== void 0 || maximum !== void 0) {
|
|
20204
|
-
assertQuantityRange(
|
|
20205
|
-
minimum ?? int32(own(item, "quantityMinimum"), "current quantityMinimum", 0),
|
|
20206
|
-
maximum ?? int32(own(item, "quantityMaximum"), "current quantityMaximum")
|
|
20207
|
-
);
|
|
20208
|
-
}
|
|
20209
|
-
const onHand = own(data, "quantityOnHand");
|
|
20210
|
-
if (typeof onHand !== "number") return;
|
|
20211
|
-
const picked = int32(own(item, "quantityPicked"), "current quantityPicked");
|
|
20212
|
-
const reserved = int32(own(item, "quantityReserved"), "current quantityReserved");
|
|
20213
|
-
if (onHand < picked + reserved) fail2("quantityOnHand must be at least quantityPicked plus quantityReserved");
|
|
20214
|
-
const productId = int32(own(item, "productID"), "current productID", 1);
|
|
20215
|
-
if (await productIsSerialized(http, productId, checkedBaseUrl, maxRetries)) fail2("quantityOnHand is read-only on update for a serialized product");
|
|
20450
|
+
if (!isRecord2(current) || !Object.hasOwn(current, "id")) fail2("current record requires its own id");
|
|
20451
|
+
if (parseIdentifier(current.id, "inventory_locations: current id") !== id) fail2("current record id must match the requested id");
|
|
20452
|
+
if (Object.hasOwn(value, "isActive") && value.isActive === false && (!Object.hasOwn(current, "isDefault") || current.isDefault !== false)) fail2("inactivation requires a fresh current isDefault value explicitly false; default or unknown locations cannot be inactivated");
|
|
20216
20453
|
}
|
|
20217
20454
|
|
|
20218
20455
|
// src/resources/base/types.ts
|
|
@@ -22771,6 +23008,11 @@ var MutationBase = class extends MetaBase {
|
|
|
22771
23008
|
current = currentRecord ?? (parentId === void 0 ? await this.getGlobal(id, true, this.config.key === "knowledge_base_categories" || partialCollection !== void 0 ? opts.maxRetries : void 0, partialCollection?.checkedBaseUrl) : this.config.attachmentGet ? await this.getScopedModel(parentId, id, true) : await this.getScopedRaw(parentId, id, true));
|
|
22772
23009
|
} catch (err) {
|
|
22773
23010
|
if (err instanceof NotFoundError) {
|
|
23011
|
+
if (this.config.key === "inventory_items" && opts.expectedInventoryFacts !== void 0) {
|
|
23012
|
+
if (err.httpStatus === 200) inventoryFactsStale(operation);
|
|
23013
|
+
Object.assign(err, { notSent: true });
|
|
23014
|
+
throw err;
|
|
23015
|
+
}
|
|
22774
23016
|
const reasons = EMPTY_REASON_STAMPS[this.config.key];
|
|
22775
23017
|
const updateReason = reasons?.update ?? (partialCollection === void 0 ? void 0 : reasons?.get);
|
|
22776
23018
|
checks.push({
|
|
@@ -25160,6 +25402,7 @@ var GenericResource = class extends BaseResource {
|
|
|
25160
25402
|
}
|
|
25161
25403
|
async create(a, b = void 0, c = void 0) {
|
|
25162
25404
|
this.requireOp("create");
|
|
25405
|
+
rejectInventoryFactsOption(isIdentifier(a) ? c : b, `${this.config.key}.create`);
|
|
25163
25406
|
if (isIdentifier(a)) {
|
|
25164
25407
|
if (this.config.opForms?.create === "global") throw new OperationNotSupportedError(this.config.key, "create");
|
|
25165
25408
|
const parentId = this.config.key === "knowledge_base_articles" ? articleParent(a) : a;
|
|
@@ -25183,11 +25426,10 @@ var GenericResource = class extends BaseResource {
|
|
|
25183
25426
|
}
|
|
25184
25427
|
if (this.config.opForms?.create === "scoped") throw new OperationNotSupportedError(this.config.key, "create");
|
|
25185
25428
|
if (this.config.key === "inventory_items") {
|
|
25186
|
-
const body =
|
|
25187
|
-
const opts2 = snapshotInventoryItemOptions(b);
|
|
25429
|
+
const { body, opts: opts2 } = captureInventoryItemCall(a, b, true);
|
|
25188
25430
|
const checkedBaseUrl = this.http.baseUrl;
|
|
25189
25431
|
try {
|
|
25190
|
-
await guardInventoryItemCreate(this.http, body, checkedBaseUrl, opts2.maxRetries);
|
|
25432
|
+
await guardInventoryItemCreate(this.http, body, checkedBaseUrl, opts2.maxRetries, opts2.expectedInventoryFacts);
|
|
25191
25433
|
} catch (error) {
|
|
25192
25434
|
if (error instanceof AutotaskError) Object.assign(error, { notSent: true });
|
|
25193
25435
|
throw error;
|
|
@@ -25204,6 +25446,7 @@ var GenericResource = class extends BaseResource {
|
|
|
25204
25446
|
}
|
|
25205
25447
|
async update(a, b = void 0, c = void 0, d = void 0) {
|
|
25206
25448
|
this.requireOp("update");
|
|
25449
|
+
rejectInventoryFactsOption(isIdentifier(b) ? d : c, `${this.config.key}.update`);
|
|
25207
25450
|
if (isIdentifier(a) && isIdentifier(b)) {
|
|
25208
25451
|
if (this.config.opForms?.update === "global") throw new OperationNotSupportedError(this.config.key, "update");
|
|
25209
25452
|
const parentId = this.config.key === "knowledge_base_articles" ? articleParent(a) : a;
|
|
@@ -25226,16 +25469,15 @@ var GenericResource = class extends BaseResource {
|
|
|
25226
25469
|
if (this.config.opForms?.update === "scoped") throw new OperationNotSupportedError(this.config.key, "update");
|
|
25227
25470
|
if (this.config.key === "inventory_items") {
|
|
25228
25471
|
const id2 = inventoryItemId(a);
|
|
25229
|
-
const body =
|
|
25230
|
-
const opts2 = snapshotInventoryItemOptions(c);
|
|
25472
|
+
const { body, opts: opts2 } = captureInventoryItemCall(b, c, false);
|
|
25231
25473
|
const checkedBaseUrl = this.http.baseUrl;
|
|
25232
|
-
const checkCurrent = (current) => checkInventoryItemCurrent(this.http, body, current, id2, checkedBaseUrl, opts2.maxRetries);
|
|
25474
|
+
const checkCurrent = (current) => checkInventoryItemCurrent(this.http, body, current, id2, checkedBaseUrl, opts2.maxRetries, opts2.expectedInventoryFacts);
|
|
25233
25475
|
if (opts2.dryRun === true) return this.runUpdateDryRun(id2, body, opts2, void 0, void 0, { checkCurrent, checkedBaseUrl });
|
|
25234
25476
|
try {
|
|
25235
25477
|
await checkCurrent(await this.getGlobal(id2, true, opts2.maxRetries, checkedBaseUrl));
|
|
25236
25478
|
} catch (error) {
|
|
25237
25479
|
if (error instanceof AutotaskError) Object.assign(error, { notSent: true });
|
|
25238
|
-
|
|
25480
|
+
rethrowInventoryGuardError(error, opts2.expectedInventoryFacts, "inventory_items.update");
|
|
25239
25481
|
}
|
|
25240
25482
|
return this.updateGlobal(id2, body, opts2, "PATCH", checkedBaseUrl);
|
|
25241
25483
|
}
|
|
@@ -25269,6 +25511,7 @@ var GenericResource = class extends BaseResource {
|
|
|
25269
25511
|
}
|
|
25270
25512
|
async delete(a, b = void 0, c = void 0) {
|
|
25271
25513
|
this.requireOp("delete");
|
|
25514
|
+
rejectInventoryFactsOption(isIdentifier(b) ? c : b, `${this.config.key}.delete`);
|
|
25272
25515
|
if (isIdentifier(a) && isIdentifier(b)) {
|
|
25273
25516
|
if (this.config.opForms?.delete === "global") throw new OperationNotSupportedError(this.config.key, "delete");
|
|
25274
25517
|
const parentId = this.config.key === "knowledge_base_articles" ? articleParent(a) : a;
|
|
@@ -31341,7 +31584,7 @@ async function wipHours(client, opts) {
|
|
|
31341
31584
|
} else {
|
|
31342
31585
|
const contractIds = positiveIds2(wipIn.map((e) => e["contractID"]));
|
|
31343
31586
|
gate(chunks2(contractIds.length) + (contractIds.length > 0 ? 1 : 0), "before label reads", { contracts: contractIds.length });
|
|
31344
|
-
const [contracts,
|
|
31587
|
+
const [contracts, types2] = await readTasks(http, [
|
|
31345
31588
|
() => readChunks2(http, "/V1.0/Contracts", contractIds, ["contractType"]),
|
|
31346
31589
|
async () => contractIds.length > 0 ? (await readPicklists(http, "/V1.0/Contracts", OP10)).get("contractType") : void 0
|
|
31347
31590
|
]);
|
|
@@ -31349,7 +31592,7 @@ async function wipHours(client, opts) {
|
|
|
31349
31592
|
const bad = contractIds.filter((id) => typeof typeOf(id) !== "number");
|
|
31350
31593
|
if (bad.length > 0) throw unresolved("contracts", bad);
|
|
31351
31594
|
keyOfEntry = (e) => num(e["contractID"]) > 0 ? typeOf(num(e["contractID"])) : null;
|
|
31352
|
-
for (const [id, label] of
|
|
31595
|
+
for (const [id, label] of types2 ?? []) labels.set(id, { label });
|
|
31353
31596
|
}
|
|
31354
31597
|
const approvalData = entries.some((e) => isApproved(e));
|
|
31355
31598
|
const acc = () => ({ entries: 0, worked: 0, toBill: 0, approved: 0 });
|
|
@@ -31540,7 +31783,7 @@ async function nonChargeableWork(client, opts) {
|
|
|
31540
31783
|
const contractIds = distinctIds(ncLines.map((x) => x.line["contractID"]), 1);
|
|
31541
31784
|
const typed = v.groupBy === "contractType";
|
|
31542
31785
|
gate(chunks3(contractIds.length) + (typed && contractIds.length > 0 ? 1 : 0) + (v.includeUnpostedTime ? 1 : 0), "before label reads", { contracts: contractIds.length });
|
|
31543
|
-
const [contracts,
|
|
31786
|
+
const [contracts, types2] = await readTasks(http, [
|
|
31544
31787
|
() => readChunks3(http, "/V1.0/Contracts", contractIds, [typed ? "contractType" : "contractName"]),
|
|
31545
31788
|
async () => typed && contractIds.length > 0 ? (await readPicklists(http, "/V1.0/Contracts", OP11)).get("contractType") : void 0
|
|
31546
31789
|
]);
|
|
@@ -31551,7 +31794,7 @@ async function nonChargeableWork(client, opts) {
|
|
|
31551
31794
|
if (!typed) return num(line["contractID"]);
|
|
31552
31795
|
return isId(c["contractType"]) ? c["contractType"] : UNRESOLVED;
|
|
31553
31796
|
};
|
|
31554
|
-
if (typed) for (const [id, label] of
|
|
31797
|
+
if (typed) for (const [id, label] of types2 ?? []) labels.set(id, { label });
|
|
31555
31798
|
else for (const [id, r] of contracts) labels.set(Number(id), typeof r["contractName"] === "string" ? { name: r["contractName"] } : {});
|
|
31556
31799
|
}
|
|
31557
31800
|
const cells = /* @__PURE__ */ new Map();
|
|
@@ -31729,8 +31972,37 @@ function bufferResult(buf) {
|
|
|
31729
31972
|
};
|
|
31730
31973
|
}
|
|
31731
31974
|
var PUBLIC_INVOKE_OPTION_KEYS = INVOKE_OPTION_KEYS.filter((key) => key !== "mode");
|
|
31732
|
-
function
|
|
31975
|
+
function snapshotInventoryInvokeOptions(options, operation, mode) {
|
|
31976
|
+
const { descriptors, expectedInventoryFacts: facts } = captureInventoryOptionDescriptors(options);
|
|
31977
|
+
if (Object.getOwnPropertySymbols(descriptors).length > 0) throw new AutotaskConfigError("inventory_items: invoke options must use string keys", { operation });
|
|
31978
|
+
const applyFlag = Object.hasOwn(descriptors, "dryRun") ? descriptors.dryRun : void 0;
|
|
31979
|
+
for (const key of PUBLIC_INVOKE_OPTION_KEYS) {
|
|
31980
|
+
if (key === "expectedInventoryFacts" || Object.hasOwn(descriptors, key)) continue;
|
|
31981
|
+
for (let owner = Object.getPrototypeOf(options); owner !== null && owner !== Object.prototype; owner = Object.getPrototypeOf(owner)) {
|
|
31982
|
+
const descriptor2 = Object.getOwnPropertyDescriptor(owner, key);
|
|
31983
|
+
if (descriptor2 !== void 0) {
|
|
31984
|
+
descriptors[key] = descriptor2;
|
|
31985
|
+
break;
|
|
31986
|
+
}
|
|
31987
|
+
}
|
|
31988
|
+
}
|
|
31989
|
+
const captured = /* @__PURE__ */ Object.create(null);
|
|
31990
|
+
for (const [key, descriptor2] of Object.entries(descriptors)) captured[key] = Object.hasOwn(descriptor2, "value") ? descriptor2.value : void 0;
|
|
31991
|
+
validateInvokeOptions(captured, operation);
|
|
31992
|
+
if (facts !== void 0 && Object.values(descriptors).some((descriptor2) => !Object.hasOwn(descriptor2, "value"))) throw new AutotaskConfigError("inventory_items: approved options must be data properties; accessors are unsupported", { operation });
|
|
31993
|
+
const applyRequested = applyFlag !== void 0 && Object.hasOwn(applyFlag, "value") && applyFlag.value === false;
|
|
31994
|
+
for (const [key, descriptor2] of Object.entries(descriptors)) {
|
|
31995
|
+
if (key === "expectedInventoryFacts" || Object.hasOwn(descriptor2, "value")) continue;
|
|
31996
|
+
captured[key] = descriptor2.get === void 0 ? void 0 : Reflect.apply(descriptor2.get, options, []);
|
|
31997
|
+
}
|
|
31998
|
+
captured.expectedInventoryFacts = facts;
|
|
31999
|
+
captured.dryRun = applyRequested || captured.dryRun !== false ? captured.dryRun : void 0;
|
|
32000
|
+
return Object.assign(captured, { mode });
|
|
32001
|
+
}
|
|
32002
|
+
function snapshotInvokeOptions(options, operation, mode) {
|
|
32003
|
+
if (operation === "inventory_items.create" || operation === "inventory_items.update") return snapshotInventoryInvokeOptions(options, operation, mode);
|
|
31733
32004
|
if (!isRecord2(options)) throw new AutotaskConfigError("invoke: options must be an object");
|
|
32005
|
+
rejectInventoryFactsOption(options, operation);
|
|
31734
32006
|
const applyFlag = Object.getOwnPropertyDescriptor(options, "dryRun");
|
|
31735
32007
|
const applyRequested = applyFlag !== void 0 && Object.hasOwn(applyFlag, "value") && applyFlag.value === false;
|
|
31736
32008
|
let confirmation;
|
|
@@ -31746,7 +32018,8 @@ function snapshotInvokeOptions(options, mode) {
|
|
|
31746
32018
|
const dryRun = options.dryRun;
|
|
31747
32019
|
const captured = snapshotFields(options, PUBLIC_INVOKE_OPTION_KEYS, {
|
|
31748
32020
|
dryRun: applyRequested || dryRun !== false ? dryRun : void 0,
|
|
31749
|
-
confirm
|
|
32021
|
+
confirm,
|
|
32022
|
+
expectedInventoryFacts: void 0
|
|
31750
32023
|
});
|
|
31751
32024
|
return Object.assign(/* @__PURE__ */ Object.create(null), captured, { mode });
|
|
31752
32025
|
}
|
|
@@ -31762,6 +32035,7 @@ async function resolveRecord(operation) {
|
|
|
31762
32035
|
}
|
|
31763
32036
|
function governPreRequest(record, operation, opts) {
|
|
31764
32037
|
validateInvokeOptions(opts, operation);
|
|
32038
|
+
if (opts.expectedInventoryFacts !== void 0) rejectInventoryFactsOption(opts, operation);
|
|
31765
32039
|
const mode = opts.mode;
|
|
31766
32040
|
if (mode !== void 0 && MODE_BY_EFFECT[record.effect] !== mode) {
|
|
31767
32041
|
throw new AutotaskConfigError(crossModeRefusal(operation, record.effect, mode), { operation });
|
|
@@ -31885,6 +32159,7 @@ var BAG_RIDING_ARGS = {
|
|
|
31885
32159
|
function buildMutationOpts(opts, isWrite) {
|
|
31886
32160
|
const dryRun = isWrite ? opts.dryRun !== false : false;
|
|
31887
32161
|
const mutationOpts = { dryRun };
|
|
32162
|
+
if (opts.expectedInventoryFacts !== void 0) mutationOpts.expectedInventoryFacts = opts.expectedInventoryFacts;
|
|
31888
32163
|
if (isWrite && opts.lastModifiedDate !== void 0) {
|
|
31889
32164
|
mutationOpts.lastModifiedDate = opts.lastModifiedDate;
|
|
31890
32165
|
}
|
|
@@ -31986,6 +32261,10 @@ async function runPreRequestPass(ctx) {
|
|
|
31986
32261
|
}
|
|
31987
32262
|
async function prepareInvocation(client, operation, argsIn, opts, streaming = false) {
|
|
31988
32263
|
const record = await resolveRecord(operation);
|
|
32264
|
+
if (operation === "inventory_items.create" || operation === "inventory_items.update") {
|
|
32265
|
+
governPreRequest(record, operation, opts);
|
|
32266
|
+
snapshotInventoryMutationOptions(opts);
|
|
32267
|
+
}
|
|
31989
32268
|
const resolvedArgs = resolveDispatchArgs(record, argsIn);
|
|
31990
32269
|
const boundedQuery = record.kind === "primitive" && record.operation === "query";
|
|
31991
32270
|
const countedQuery = record.kind === "primitive" && record.operation === "count";
|
|
@@ -32027,14 +32306,16 @@ async function invokeMode(client, operation, argsIn = [], opts = {}) {
|
|
|
32027
32306
|
return scopeNote !== void 0 && finished !== null && typeof finished === "object" ? { ...finished, scopeNote } : finished;
|
|
32028
32307
|
}
|
|
32029
32308
|
async function invoke(client, operation, args = [], opts = {}) {
|
|
32030
|
-
|
|
32309
|
+
const capturedArgs = captureInventoryInvocationArgs(operation, args);
|
|
32310
|
+
const capturedOpts = snapshotInvokeOptions(opts, operation);
|
|
32311
|
+
return invokeMode(client, operation, capturedArgs(capturedOpts.expectedInventoryFacts === void 0), capturedOpts);
|
|
32031
32312
|
}
|
|
32032
32313
|
async function invokeRead(client, operation, args = [], opts = {}) {
|
|
32033
|
-
return invokeMode(client, operation, args, snapshotInvokeOptions(opts, "read"));
|
|
32314
|
+
return invokeMode(client, operation, args, snapshotInvokeOptions(opts, operation, "read"));
|
|
32034
32315
|
}
|
|
32035
32316
|
async function invokeReadPages(client, operation, args, onPage, opts = {}) {
|
|
32036
32317
|
if (typeof onPage !== "function") throw new AutotaskConfigError("invokeReadPages: onPage must be a function", { operation });
|
|
32037
|
-
const prepared = await prepareInvocation(client, operation, args, snapshotInvokeOptions(opts, "read"), true);
|
|
32318
|
+
const prepared = await prepareInvocation(client, operation, args, snapshotInvokeOptions(opts, operation, "read"), true);
|
|
32038
32319
|
prepared.pageSession.guard();
|
|
32039
32320
|
const consume = prepared.method;
|
|
32040
32321
|
const result = await consume.call(prepared.holder, prepared.callArgs[0], onPage);
|
|
@@ -32042,10 +32323,12 @@ async function invokeReadPages(client, operation, args, onPage, opts = {}) {
|
|
|
32042
32323
|
return prepared.scopeNote === void 0 ? result : { ...result, scopeNote: prepared.scopeNote };
|
|
32043
32324
|
}
|
|
32044
32325
|
async function invokeWrite(client, operation, args = [], opts = {}) {
|
|
32045
|
-
|
|
32326
|
+
const capturedArgs = captureInventoryInvocationArgs(operation, args);
|
|
32327
|
+
const capturedOpts = snapshotInvokeOptions(opts, operation, "write");
|
|
32328
|
+
return invokeMode(client, operation, capturedArgs(capturedOpts.expectedInventoryFacts === void 0), capturedOpts);
|
|
32046
32329
|
}
|
|
32047
32330
|
async function invokeDelete(client, operation, args = [], opts = {}) {
|
|
32048
|
-
return invokeMode(client, operation, args, snapshotInvokeOptions(opts, "delete"));
|
|
32331
|
+
return invokeMode(client, operation, args, snapshotInvokeOptions(opts, operation, "delete"));
|
|
32049
32332
|
}
|
|
32050
32333
|
|
|
32051
32334
|
// src/resources/special/_shared/compositeParts.ts
|
|
@@ -32204,4 +32487,4 @@ var ContractsResource = class extends GenericResource {
|
|
|
32204
32487
|
}
|
|
32205
32488
|
};
|
|
32206
32489
|
|
|
32207
|
-
export { AGGREGATE_DATE_BUCKETS, AGGREGATE_DEFAULT_LIMIT, AGGREGATE_DEFAULT_TOP, AGGREGATE_TOP_MAX, AutotaskAbortError, AutotaskConfigError, AutotaskError, AutotaskNetworkError, AutotaskTimeoutError, CREATE_BLOCKER_KINDS, CREDENTIAL_ENV_LOAD_ACTION, CREDENTIAL_SHAPE_POINTER, CompaniesResource, ConfirmationRequiredError, ConflictError, ContractsResource, DEFAULT_ZONE, DeleteBoundaryError, EXPAND_RESOURCE_NAMES_MAX_IDS, EmptyResponseError, FETCH_BY_IDS_CHUNK_SIZE, FETCH_BY_IDS_MAX_ITEMS, FIELD_CACHE_KINDS, FIELD_CATALOG_HONESTY_NOTE, GenericResource, HostPolicyDeniedError, HttpClient, INVOKE_OPTION_KEYS, InvoicesResource, MAX_FIELD_CATALOG_WIRE, MIN_FIELD_CATALOG_MAX_BYTES, MIN_PREFIX_SUMMARY_LENGTH, MaintenanceError, MarkerUnsafeIdError, MoveRefusedError, NotFoundError, OperationNotSupportedError, PARAMS_BAG_KEYS, PICKLIST_VALUE_NOT_SERVED_NOTE, PaginationLimitError, QueryTooLongError, RELATIONSHIP_MAP, RateLimitError, RecoveryTruncatedError, ResolutionError, ResponseRejectedError, SIMPLE_RESOURCES, ScopeRequiredError, StaleObjectError, TICKET_LABEL_FIELDS, TimeEntriesResource, TtlCache, UI_LINK_ENTITIES, UNSCOPED_WALK_THRESHOLD, UnexpectedContentTypeError, WORKFLOW_RESOURCES, ZONES, addLabelSibling, addNameSibling, aggregate, arAging, buildDryRunResult, buildQueryRequest, buildReadCache, buildUiLink, cachedRecordGet, clientOf, compositePart, compositePartLimit, createGuidance, createNamePlan, credentialShapeProblem, credentialValueSummary, cursorToPath, dateBucketLabel, effectiveRequiredFields, errorFromStatus, expandResourceNames, fetchByIds, fieldCatalog, foldFlattenedOpts, formatVendorDetail, invoke, invokeDelete, invokeRead, invokeReadPages, invokeWrite, isAutotaskError, isClosedStatus, isDateYMD, isDeterministicVendor500, isRecord2 as isRecord, joinedCompositePart, mergeDetails, mergePartialBody, needsConfirmation, nextActionFor, nonChargeableWork, notPersistedFields, openStatusFilter, openTicketsOfPart, parseIdentifier, parseVendorErrors, portfolioMargin, queryRows, readTasks, recurringRevenue, refuse2 as refuse, relationshipMap, resolveAny, resolveCompositeNames, resolveConfig, resolveCredentials, resolveLineOfBusinessChain, resolveStaff, resolveTicketStatusSemantics, revenueRollup, runBounded, runMove, runWithSignal, sanitiseResult, searchAcrossResources, suspendCompanyIndex, uiLink, uiLinkFor, unknownKeysRefusal, unwrapItem, unwrapItems, unwrapOperation, validateDispatchArgs, validateInvokeOptions, validateParamsBag, vendorId, wipHours, zoneUrl };
|
|
32490
|
+
export { AGGREGATE_DATE_BUCKETS, AGGREGATE_DEFAULT_LIMIT, AGGREGATE_DEFAULT_TOP, AGGREGATE_TOP_MAX, AutotaskAbortError, AutotaskConfigError, AutotaskError, AutotaskNetworkError, AutotaskTimeoutError, CREATE_BLOCKER_KINDS, CREDENTIAL_ENV_LOAD_ACTION, CREDENTIAL_SHAPE_POINTER, CompaniesResource, ConfirmationRequiredError, ConflictError, ContractsResource, DEFAULT_ZONE, DeleteBoundaryError, EXPAND_RESOURCE_NAMES_MAX_IDS, EmptyResponseError, FETCH_BY_IDS_CHUNK_SIZE, FETCH_BY_IDS_MAX_ITEMS, FIELD_CACHE_KINDS, FIELD_CATALOG_HONESTY_NOTE, GenericResource, HostPolicyDeniedError, HttpClient, INVOKE_OPTION_KEYS, InvoicesResource, MAX_FIELD_CATALOG_WIRE, MIN_FIELD_CATALOG_MAX_BYTES, MIN_PREFIX_SUMMARY_LENGTH, MaintenanceError, MarkerUnsafeIdError, MoveRefusedError, NotFoundError, OperationNotSupportedError, PARAMS_BAG_KEYS, PICKLIST_VALUE_NOT_SERVED_NOTE, PaginationLimitError, QueryTooLongError, RELATIONSHIP_MAP, RateLimitError, RecoveryTruncatedError, ResolutionError, ResponseRejectedError, SIMPLE_RESOURCES, ScopeRequiredError, StaleObjectError, TICKET_LABEL_FIELDS, TimeEntriesResource, TtlCache, UI_LINK_ENTITIES, UNSCOPED_WALK_THRESHOLD, UnexpectedContentTypeError, WORKFLOW_RESOURCES, ZONES, addLabelSibling, addNameSibling, aggregate, arAging, buildDryRunResult, buildQueryRequest, buildReadCache, buildUiLink, cachedRecordGet, clientOf, compositePart, compositePartLimit, createGuidance, createNamePlan, credentialShapeProblem, credentialValueSummary, cursorToPath, dateBucketLabel, effectiveRequiredFields, errorFromStatus, expandResourceNames, fetchByIds, fieldCatalog, foldFlattenedOpts, formatVendorDetail, inventoryItemGuardFacts, invoke, invokeDelete, invokeRead, invokeReadPages, invokeWrite, isAutotaskError, isClosedStatus, isDateYMD, isDeterministicVendor500, isRecord2 as isRecord, joinedCompositePart, mergeDetails, mergePartialBody, needsConfirmation, nextActionFor, nonChargeableWork, notPersistedFields, openStatusFilter, openTicketsOfPart, parseIdentifier, parseVendorErrors, portfolioMargin, queryRows, readTasks, recurringRevenue, refuse2 as refuse, rejectInventoryFactsOption, relationshipMap, resolveAny, resolveCompositeNames, resolveConfig, resolveCredentials, resolveLineOfBusinessChain, resolveStaff, resolveTicketStatusSemantics, revenueRollup, runBounded, runMove, runWithSignal, sanitiseResult, searchAcrossResources, suspendCompanyIndex, uiLink, uiLinkFor, unknownKeysRefusal, unwrapItem, unwrapItems, unwrapOperation, validateDispatchArgs, validateInvokeOptions, validateParamsBag, vendorId, wipHours, zoneUrl };
|