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