node-autotask 0.91.0 → 0.92.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/MCP_TOOL_CATALOG.json +152 -9
  3. package/README.md +1 -1
  4. package/capabilities.json +575 -28
  5. package/dist/capabilities-data.js +574 -27
  6. package/dist/capabilities.cjs +4 -4
  7. package/dist/capabilities.js +1 -1
  8. package/dist/{chunk-43ADHLZJ.js → chunk-2MC3LDZU.js} +3 -3
  9. package/dist/{chunk-YFC5VAKK.cjs → chunk-ATDGRAX2.cjs} +31 -30
  10. package/dist/{chunk-Y2KXGSWM.js → chunk-ELAU2MT5.js} +3 -2
  11. package/dist/{chunk-RXXITZH4.cjs → chunk-H24SV774.cjs} +377 -114
  12. package/dist/{chunk-5PUHGPKG.cjs → chunk-JPZ7M7QI.cjs} +200 -200
  13. package/dist/{chunk-2GP7W6QB.js → chunk-NQNAEA23.js} +372 -109
  14. package/dist/{chunk-KRYDLTY3.cjs → chunk-QXJQIZCT.cjs} +3 -3
  15. package/dist/{chunk-WAHRZDV4.js → chunk-XAOWO42G.js} +2 -2
  16. package/dist/{index-Dy92Xbpv.d.cts → index-B9y5IwT1.d.cts} +41 -1
  17. package/dist/{index-Dy92Xbpv.d.ts → index-B9y5IwT1.d.ts} +41 -1
  18. package/dist/{index-C3jXvpXZ.d.ts → index-U7Lepdm2.d.ts} +8 -5
  19. package/dist/{index-BfGOllfY.d.cts → index-lWek2NrV.d.cts} +8 -5
  20. package/dist/index.cjs +85 -85
  21. package/dist/index.d.cts +3 -3
  22. package/dist/index.d.ts +3 -3
  23. package/dist/index.js +5 -5
  24. package/dist/operations/index.cjs +51 -51
  25. package/dist/operations/index.d.cts +6 -4
  26. package/dist/operations/index.d.ts +6 -4
  27. package/dist/operations/index.js +2 -2
  28. package/dist/pool.cjs +12 -12
  29. package/dist/pool.d.cts +1 -1
  30. package/dist/pool.d.ts +1 -1
  31. package/dist/pool.js +4 -4
  32. package/dist/resources/index.cjs +27 -27
  33. package/dist/resources/index.d.cts +2 -2
  34. package/dist/resources/index.d.ts +2 -2
  35. package/dist/resources/index.js +3 -3
  36. package/dist/types/index.d.cts +1 -1
  37. package/dist/types/index.d.ts +1 -1
  38. package/docs/API.md +3 -2
  39. package/examples/mcp/manifest.ts +1 -1
  40. package/examples/mcp/tools-mode.ts +15 -6
  41. package/examples/mcp/tools-read.ts +8 -2
  42. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- import { loadCapabilityRecords } from './chunk-43ADHLZJ.js';
1
+ 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';
@@ -1586,6 +1586,11 @@ function countUdfConditions(conditions) {
1586
1586
  }
1587
1587
  return n;
1588
1588
  }
1589
+ function assertSupportedUdfConditions(conditions, operation) {
1590
+ if (operation.startsWith("inventory_items.") && conditions !== void 0 && countUdfConditions(conditions) > 0) {
1591
+ throw new AutotaskConfigError("InventoryItems has no record UDFs. Filter on its documented fields.", { operation });
1592
+ }
1593
+ }
1589
1594
  function serializeFilter(filter) {
1590
1595
  return JSON.stringify(filter);
1591
1596
  }
@@ -10965,6 +10970,65 @@ var RELATIONSHIP_MAP = {
10965
10970
  "deleteBoundary": null,
10966
10971
  "markerField": null
10967
10972
  },
10973
+ "inventory_items": {
10974
+ "resource": "inventory_items",
10975
+ "apiEntity": "InventoryItem",
10976
+ "kind": "entity",
10977
+ "path": "InventoryItems",
10978
+ "parentScoped": false,
10979
+ "tier": "extended",
10980
+ "workflowResource": false,
10981
+ "group": "A",
10982
+ "parent": null,
10983
+ "children": [],
10984
+ "naturalKeys": {
10985
+ "hasSearch": false,
10986
+ "searchCovers": null,
10987
+ "findBy": []
10988
+ },
10989
+ "blindSurfaces": null,
10990
+ "zoneFacts": {
10991
+ "createRequiredSet": [
10992
+ "inventoryLocationID",
10993
+ "productID",
10994
+ "quantityMinimum",
10995
+ "quantityMaximum",
10996
+ "quantityOnHand"
10997
+ ],
10998
+ "createGuidance": {
10999
+ "createOp": "inventory_items.create",
11000
+ "parentScoped": false,
11001
+ "liveProvenPrefix": [],
11002
+ "unproven": true,
11003
+ "blocker": {
11004
+ "kind": "unknown",
11005
+ "message": "Inventory access, an active location, a visible product and a unique product-location pair are required.",
11006
+ "remedy": "Read product and location metadata, supply the required quantities and preview before apply.",
11007
+ "requires": {
11008
+ "allOf": [
11009
+ "inventoryLocationID",
11010
+ "productID",
11011
+ "quantityMinimum",
11012
+ "quantityMaximum",
11013
+ "quantityOnHand"
11014
+ ]
11015
+ }
11016
+ },
11017
+ "vendorEvidence": [
11018
+ "https://www.autotask.net/help/developerhelp/Content/APIs/REST/Entities/InventoryItemsEntity.htm"
11019
+ ],
11020
+ "deleteBoundary": {
11021
+ "available": false,
11022
+ "note": "The specification defines no public DELETE for InventoryItems."
11023
+ }
11024
+ }
11025
+ },
11026
+ "deleteBoundary": {
11027
+ "note": "The specification defines no public DELETE for InventoryItems. A created item cannot be removed through that API.",
11028
+ "proof": "spec-derived"
11029
+ },
11030
+ "markerField": null
11031
+ },
10968
11032
  "inventory_locations": {
10969
11033
  "resource": "inventory_locations",
10970
11034
  "apiEntity": "InventoryLocation",
@@ -11171,6 +11235,7 @@ var DELETE_BOUNDARY_NOTES = {
11171
11235
  "user_defined_field_list_items": "the vendor defines no DELETE for user_defined_field_list_items (spec-derived: the vendored api-docs.json defines no DELETE on the standalone or parent-scoped ListItems paths) \u2014 a picklist value cannot be deleted through the API; deactivation is via isActive (vendor soft-removal); hard cleanup is UI-only.",
11172
11236
  "task_notes": "The vendor defines no DELETE for task_notes (spec-derived); a created task note cannot be removed through the public API.",
11173
11237
  "time_off_requests": "The vendor defines no DELETE for time-off requests; cancel through time_off_requests.update using the Canceled status from exposed field metadata. Cancellation is leave management, not timesheet unposting.",
11238
+ "inventory_items": "The specification defines no public DELETE for InventoryItems. A created item cannot be removed through that API.",
11174
11239
  "inventory_locations": "The vendor defines no DELETE for inventory_locations (spec-derived); a created inventory location cannot be removed through the public API."
11175
11240
  };
11176
11241
  var RESPONSE_DRIFT_MARKERS = {
@@ -14098,6 +14163,34 @@ var CREATE_GUIDANCE = {
14098
14163
  "note": null
14099
14164
  }
14100
14165
  },
14166
+ {
14167
+ "resource": "inventory_items",
14168
+ "createOp": "inventory_items.create",
14169
+ "parentScoped": false,
14170
+ "liveProvenPrefix": [],
14171
+ "unproven": true,
14172
+ "blocker": {
14173
+ "kind": "unknown",
14174
+ "message": "Inventory access, an active location, a visible product and a unique product-location pair are required.",
14175
+ "remedy": "Read product and location metadata, supply the required quantities and preview before apply.",
14176
+ "requires": {
14177
+ "allOf": [
14178
+ "inventoryLocationID",
14179
+ "productID",
14180
+ "quantityMinimum",
14181
+ "quantityMaximum",
14182
+ "quantityOnHand"
14183
+ ]
14184
+ }
14185
+ },
14186
+ "vendorEvidence": [
14187
+ "https://www.autotask.net/help/developerhelp/Content/APIs/REST/Entities/InventoryItemsEntity.htm"
14188
+ ],
14189
+ "deleteBoundary": {
14190
+ "available": false,
14191
+ "note": "The specification defines no public DELETE for InventoryItems."
14192
+ }
14193
+ },
14101
14194
  {
14102
14195
  "resource": "inventory_locations",
14103
14196
  "createOp": "inventory_locations.create",
@@ -15703,7 +15796,7 @@ var CREATE_GUIDANCE = {
15703
15796
  }
15704
15797
  ],
15705
15798
  "counts": {
15706
- "total": 117,
15799
+ "total": 118,
15707
15800
  "byKind": {
15708
15801
  "ok": 41,
15709
15802
  "blind-reference": 16,
@@ -15713,7 +15806,7 @@ var CREATE_GUIDANCE = {
15713
15806
  "resource-role-pair": 2,
15714
15807
  "delete-absent": 0,
15715
15808
  "non-mutable": 0,
15716
- "unknown": 41
15809
+ "unknown": 42
15717
15810
  }
15718
15811
  }
15719
15812
  };
@@ -16493,6 +16586,10 @@ var UNTRUSTED_FIELDS_BY_RESOURCE = {
16493
16586
  "referenceLink",
16494
16587
  "title"
16495
16588
  ],
16589
+ "inventory_items": [
16590
+ "bin",
16591
+ "referenceNumber"
16592
+ ],
16496
16593
  "inventory_locations": [
16497
16594
  "locationName"
16498
16595
  ],
@@ -16964,9 +17061,9 @@ function isKnowledgeBaseRootResource(resource) {
16964
17061
  return resource === "knowledge_base_categories" || resource === "knowledge_base_articles";
16965
17062
  }
16966
17063
  function isExactRecordResource(resource) {
16967
- return resource === "inventory_locations" || resource === "internal_locations" || resource === "shipping_types" || isKnowledgeBaseRootResource(resource);
17064
+ return resource === "inventory_locations" || resource === "inventory_items" || resource === "internal_locations" || resource === "shipping_types" || isKnowledgeBaseRootResource(resource);
16968
17065
  }
16969
- var EXACT_RECORD_PATH = /^\/v1\.0\/(?:InventoryLocations|InternalLocations|ShippingTypes|KnowledgeBaseArticles|KnowledgeBaseCategories(?:\/\d+\/KnowledgeBaseArticles)?)(?:\/(query(?:\/(?:next|previous|count))?|\d+))?\/?$/i;
17066
+ var EXACT_RECORD_PATH = /^\/v1\.0\/(?:InventoryLocations|InventoryItems|InternalLocations|ShippingTypes|KnowledgeBaseArticles|KnowledgeBaseCategories(?:\/\d+\/KnowledgeBaseArticles)?)(?:\/(query(?:\/(?:next|previous|count))?|\d+))?\/?$/i;
16970
17067
  function exactRecordResponseTarget(path, method, operation) {
16971
17068
  const match = EXACT_RECORD_PATH.exec(path);
16972
17069
  if (match === null) return void 0;
@@ -17138,7 +17235,7 @@ function attachEmptyReasonDetails(err) {
17138
17235
  } : {
17139
17236
  surface,
17140
17237
  kind: "not-found",
17141
- note: isDeletedAuditRead(surface) ? "No audit log entry at this ID was visible to this API user." : resource === "internal_locations" || resource === "shipping_types" ? "No record at this ID was visible to this API user." : resource === "knowledge_base_articles" ? "No published article at this ID was visible to this API user." : `no ${resource} record exists at this id (a miss is the data, not an error condition)`,
17238
+ note: isDeletedAuditRead(surface) ? "No audit log entry at this ID was visible to this API user." : resource === "internal_locations" || resource === "shipping_types" || resource === "inventory_items" ? "No record at this ID was visible to this API user." : resource === "knowledge_base_articles" ? "No published article at this ID was visible to this API user." : `no ${resource} record exists at this id (a miss is the data, not an error condition)`,
17142
17239
  authority: `${resource}.query`,
17143
17240
  remedy: `query the ${resource} collection (a bounded queryBounded walk) or verify the id from the authority surface \u2014 do not retry the same get`
17144
17241
  };
@@ -18527,13 +18624,13 @@ async function runBounded(fn, items, opts) {
18527
18624
  const results = new Array(items.length);
18528
18625
  let next = 0;
18529
18626
  let failure;
18530
- const fail4 = (error, index) => {
18627
+ const fail5 = (error, index) => {
18531
18628
  if (failure === void 0 || opts.orderedErrors === true && index < failure.index) failure = { error, index };
18532
18629
  };
18533
18630
  const worker = async () => {
18534
18631
  while (failure === void 0 && next < items.length) {
18535
18632
  if (signal?.aborted) {
18536
- fail4(signal.reason, -1);
18633
+ fail5(signal.reason, -1);
18537
18634
  return;
18538
18635
  }
18539
18636
  const i = next++;
@@ -18543,7 +18640,7 @@ async function runBounded(fn, items, opts) {
18543
18640
  results[i] = settle ? { status: "fulfilled", value } : value;
18544
18641
  } catch (error) {
18545
18642
  if (settle) results[i] = { status: "rejected", reason: error };
18546
- else fail4(error, i);
18643
+ else fail5(error, i);
18547
18644
  }
18548
18645
  }
18549
18646
  };
@@ -20016,6 +20113,108 @@ function checkInventoryLocationCurrent(value, current, id) {
20016
20113
  if (Object.hasOwn(value, "isActive") && value.isActive === false && (!Object.hasOwn(current, "isDefault") || current.isDefault !== false)) fail("inactivation requires a fresh current isDefault value explicitly false; default or unknown locations cannot be inactivated");
20017
20114
  }
20018
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");
20216
+ }
20217
+
20019
20218
  // src/resources/base/types.ts
20020
20219
  var BOUNDED_QUERY_DEFAULT_LIMIT = 500;
20021
20220
  var BOUNDED_QUERY_MAX_LIMIT = 2500;
@@ -20183,6 +20382,7 @@ var MODEL_FIELD_SETS = {
20183
20382
  "holiday_sets": ["id", "holidaySetDescription", "holidaySetName"],
20184
20383
  "holidays": ["id", "holidayDate", "holidayName", "holidaySetID", "soapParentPropertyId"],
20185
20384
  "internal_locations": ["id", "additionalAddressInfo", "address1", "address2", "city", "country", "holidaySetId", "isDefault", "name", "postalCode", "state", "timeZone"],
20385
+ "inventory_items": ["id", "backOrderQuantity", "bin", "impersonatorCreatorResourceID", "inventoryLocationID", "productID", "quantityMaximum", "quantityMinimum", "quantityOnHand", "quantityOnOrder", "quantityPicked", "quantityReserved", "referenceNumber"],
20186
20386
  "inventory_locations": ["id", "impersonatorCreatorResourceID", "isActive", "isDefault", "locationName", "resourceID"],
20187
20387
  "inventory_products": ["id", "availableUnits", "backOrderQuantity", "bin", "createDateTime", "createdByResourceID", "inventoryLocationID", "onHandUnits", "pickedUnits", "productID", "quantityMaximum", "quantityMinimum", "referenceNumber", "reservedUnits", "unitsOnOrder"],
20188
20388
  "invoice_templates": ["id", "coveredByBlockRetainerContractLabel", "coveredByRecurringServiceFixedPricePerTicketContractLabel", "currencyNegativeFormat", "currencyPositiveFormat", "dateFormat", "displayFixedPriceContractLabor", "displayRecurringServiceContractLabor", "displaySeparateLineItemForEachTax", "displayTaxCategory", "displayTaxCategorySuperscripts", "displayZeroAmountRecurringServicesAndBundles", "groupBy", "itemizeItemsInEachGroup", "itemizeServicesAndBundles", "name", "nonBillableLaborLabel", "numberFormat", "pageLayout", "pageNumberFormat", "paymentTerms", "rateCostExpression", "showGridHeader", "showVerticalGridLines", "sortBy", "timeFormat"],
@@ -20424,27 +20624,28 @@ function validateRelationLeaves(resourceKey, conditions, op) {
20424
20624
  assertUndottedUdfField(c, op);
20425
20625
  const field = c.field;
20426
20626
  const [rel, sub, ...rest] = field.split(".");
20427
- const fail4 = (why) => {
20627
+ const fail5 = (why) => {
20428
20628
  throw new AutotaskConfigError(`${op}: relation filter "${field}" ${why} \u2014 the request was not issued`, {
20429
20629
  operation: op,
20430
20630
  suggestedAction: valid.length > 0 ? `Use ${valid.map((r) => `${r}.<${RELATION_TARGETS[r].resource} field>`).join(" or ")} (one hop; field names from operations.fieldCatalog).` : `${resourceKey} has no relation filters; filter on its own fields.`
20431
20631
  });
20432
20632
  };
20433
20633
  if (selfPrefixes(resourceKey).includes(rel)) {
20434
- if (rest.length > 0 || !sub) fail4("is not <resource>.<field> (multi-hop relations are not supported)");
20634
+ if (rest.length > 0 || !sub) fail5("is not <resource>.<field> (multi-hop relations are not supported)");
20435
20635
  continue;
20436
20636
  }
20437
- if (rest.length > 0 || !sub) fail4("is not <relation>.<field> (multi-hop relations are not supported)");
20438
- if (!valid.includes(rel)) fail4(`names an unknown relation for ${resourceKey} (valid: ${valid.join(", ") || "none"})`);
20637
+ if (rest.length > 0 || !sub) fail5("is not <relation>.<field> (multi-hop relations are not supported)");
20638
+ if (!valid.includes(rel)) fail5(`names an unknown relation for ${resourceKey} (valid: ${valid.join(", ") || "none"})`);
20439
20639
  const parentFields = MODEL_FIELD_SETS[RELATION_TARGETS[rel].resource];
20440
20640
  if (parentFields !== void 0 && modelFieldLookup(RELATION_TARGETS[rel].resource)?.(sub) !== true) {
20441
- fail4(`names a field unknown on ${RELATION_TARGETS[rel].resource}`);
20641
+ fail5(`names a field unknown on ${RELATION_TARGETS[rel].resource}`);
20442
20642
  }
20443
20643
  }
20444
20644
  };
20445
20645
  walk(conditions);
20446
20646
  }
20447
20647
  async function rewriteRelationFilters(http, resourceKey, conditions, op) {
20648
+ assertSupportedUdfConditions(conditions, op);
20448
20649
  if (!hasRelationConditions(conditions)) return void 0;
20449
20650
  const conds = conditions;
20450
20651
  validateRelationLeaves(resourceKey, conds, op);
@@ -20797,11 +20998,13 @@ var QueryBase = class {
20797
20998
  walkPageSize(params) {
20798
20999
  return clampPageSize(params?.maxRecords ?? this.defaultPageSize);
20799
21000
  }
21001
+ /** Capture mutable input for Knowledge Base and InventoryItems reads. */
20800
21002
  snapshotKnowledgeBaseQuery(params) {
20801
- if (isKnowledgeBaseRootResource(this.config.key) && isRecord2(params)) {
21003
+ const knowledgeBase = isKnowledgeBaseRootResource(this.config.key);
21004
+ if ((knowledgeBase || this.config.key === "inventory_items") && isRecord2(params)) {
20802
21005
  const captured = snapshotQueryBag(params, QUERY_BAG_KEYS);
20803
21006
  const conditions = Array.isArray(captured.filter) ? captured.filter : captured.filter?.filter;
20804
- if (conditions?.length === 0) delete captured.filter;
21007
+ if (knowledgeBase && conditions?.length === 0) delete captured.filter;
20805
21008
  return captured;
20806
21009
  }
20807
21010
  return params;
@@ -20842,7 +21045,7 @@ var QueryBase = class {
20842
21045
  }
20843
21046
  /** Stream page objects (the resource `queryPages` surface; relation filters resolve first, #281). */
20844
21047
  async *queryPageIter(params) {
20845
- const walk = await this.relationWalkParams(params, `${this.config.key}.query`);
21048
+ const walk = await this.relationWalkParams(this.snapshotKnowledgeBaseQuery(params), `${this.config.key}.query`);
20846
21049
  if (walk === void 0) return;
20847
21050
  yield* paginate(this.pageFetcher(walk), { pageSize: this.walkPageSize(walk), continueOnEmpty: this.continueAcrossEmptyPage() });
20848
21051
  }
@@ -21879,26 +22082,26 @@ var MetaBase = class _MetaBase extends QueryBase {
21879
22082
 
21880
22083
  // src/resources/special/knowledgeBaseCategories.ts
21881
22084
  function admitKnowledgeBaseCategory(data, creating, staleToken) {
21882
- const fail4 = (message) => {
22085
+ const fail5 = (message) => {
21883
22086
  throw new AutotaskConfigError(`knowledge_base_categories: ${message}`);
21884
22087
  };
21885
- if (!creating && staleToken !== void 0) fail4("no documented stale timestamp is available");
21886
- if (!isRecord2(data) || ![Object.prototype, null].includes(Object.getPrototypeOf(data))) fail4("data must be a plain record");
22088
+ if (!creating && staleToken !== void 0) fail5("no documented stale timestamp is available");
22089
+ if (!isRecord2(data) || ![Object.prototype, null].includes(Object.getPrototypeOf(data))) fail5("data must be a plain record");
21887
22090
  const body = { ...data };
21888
- for (const field of Object.keys(body)) if (!["name", "description", "parentCategoryID"].includes(field)) fail4(`${field} is not a writable KnowledgeBaseCategories field`);
22091
+ for (const field of Object.keys(body)) if (!["name", "description", "parentCategoryID"].includes(field)) fail5(`${field} is not a writable KnowledgeBaseCategories field`);
21889
22092
  for (const [field, max] of [["name", 50], ["description", 1e3]]) {
21890
22093
  const value = body[field];
21891
- if (value !== void 0 && (typeof value !== "string" || value.length > max)) fail4(`${field} must be a string of at most ${max} characters`);
22094
+ if (value !== void 0 && (typeof value !== "string" || value.length > max)) fail5(`${field} must be a string of at most ${max} characters`);
21892
22095
  }
21893
- if ((creating || body.name !== void 0) && (typeof body.name !== "string" || body.name.trim() === "")) fail4("name is required");
21894
- if (creating && body.parentCategoryID === void 0) fail4("parentCategoryID is required; choose a documented visible category rather than guessing a root id");
22096
+ if ((creating || body.name !== void 0) && (typeof body.name !== "string" || body.name.trim() === "")) fail5("name is required");
22097
+ if (creating && body.parentCategoryID === void 0) fail5("parentCategoryID is required; choose a documented visible category rather than guessing a root id");
21895
22098
  const parent = body.parentCategoryID;
21896
22099
  if (parent !== void 0) {
21897
- if (typeof parent !== "number") return fail4("parentCategoryID must be a numeric identifier");
22100
+ if (typeof parent !== "number") return fail5("parentCategoryID must be a numeric identifier");
21898
22101
  parseIdentifier(parent, "parentCategoryID");
21899
- if (parent > 2147483647) fail4("parentCategoryID must fit a signed 32-bit integer");
22102
+ if (parent > 2147483647) fail5("parentCategoryID must fit a signed 32-bit integer");
21900
22103
  }
21901
- if (!creating && !Object.values(body).some((value) => value !== void 0)) fail4("update must contain a writable field");
22104
+ if (!creating && !Object.values(body).some((value) => value !== void 0)) fail5("update must contain a writable field");
21902
22105
  return body;
21903
22106
  }
21904
22107
  function categoryReplacement(body) {
@@ -21912,45 +22115,45 @@ function categoryReplacement(body) {
21912
22115
  }
21913
22116
 
21914
22117
  // src/resources/special/knowledgeBaseArticles.ts
21915
- function fail2(detail) {
22118
+ function fail3(detail) {
21916
22119
  throw new AutotaskConfigError(`knowledge_base_articles: ${detail}`);
21917
22120
  }
21918
22121
  function reference(value, name) {
21919
- if (typeof value !== "number") fail2(`${name} must be a numeric identifier`);
22122
+ if (typeof value !== "number") fail3(`${name} must be a numeric identifier`);
21920
22123
  parseIdentifier(value, name);
21921
- if (value > 2147483647) fail2(`${name} must fit a signed 32-bit integer`);
22124
+ if (value > 2147483647) fail3(`${name} must fit a signed 32-bit integer`);
21922
22125
  return value;
21923
22126
  }
21924
22127
  function articleParent(value) {
21925
22128
  const parent = parseIdentifier(value, "parentId");
21926
- if (typeof parent !== "number" || parent > 2147483647) fail2("parentId must fit a signed 32-bit category identifier");
21927
- if (parent === 0) fail2("parentId must name an article category");
22129
+ if (typeof parent !== "number" || parent > 2147483647) fail3("parentId must fit a signed 32-bit category identifier");
22130
+ if (parent === 0) fail3("parentId must name an article category");
21928
22131
  return parent;
21929
22132
  }
21930
22133
  function admitArticle(data, parentId, creating) {
21931
22134
  const parent = articleParent(parentId);
21932
- if (!isRecord2(data) || ![Object.prototype, null].includes(Object.getPrototypeOf(data))) fail2("data must be a plain record");
22135
+ if (!isRecord2(data) || ![Object.prototype, null].includes(Object.getPrototypeOf(data))) fail3("data must be a plain record");
21933
22136
  const body = { ...data };
21934
22137
  const allowed = ["articleCategoryID", "publish", "title", "errorCodes", "keywords", "referenceLink", "isActive"];
21935
22138
  for (const key of Object.keys(body)) {
21936
- if (!allowed.includes(key)) fail2(`${key} is not a writable article root field`);
22139
+ if (!allowed.includes(key)) fail3(`${key} is not a writable article root field`);
21937
22140
  if (key !== "articleCategoryID" && body[key] === void 0) delete body[key];
21938
22141
  }
21939
22142
  for (const [field, max] of [["title", 200], ["errorCodes", 200], ["keywords", 300], ["referenceLink", 500]]) {
21940
- if (Object.hasOwn(body, field) && (typeof body[field] !== "string" || body[field].length > max)) fail2(`${field} must be a string of at most ${max} characters`);
21941
- }
21942
- if ((creating || Object.hasOwn(body, "title")) && (typeof body.title !== "string" || !body.title.trim())) fail2("title is required and cannot be blank");
21943
- if (!creating && Object.hasOwn(body, "articleCategoryID")) fail2("articleCategoryID is read-only after creation");
21944
- if (creating && String(reference(body.articleCategoryID, "articleCategoryID")) !== String(parent)) fail2("articleCategoryID must match parentId");
21945
- if ((creating || Object.hasOwn(body, "publish")) && (typeof body.publish !== "number" || !Number.isSafeInteger(body.publish) || body.publish < -2147483648 || body.publish > 2147483647)) fail2("publish must be an int32 from current field metadata");
21946
- if (Object.hasOwn(body, "isActive") && typeof body.isActive !== "boolean") fail2("isActive must be boolean");
21947
- if (!creating && !Object.keys(body).length) fail2("update must contain a writable field");
22143
+ if (Object.hasOwn(body, field) && (typeof body[field] !== "string" || body[field].length > max)) fail3(`${field} must be a string of at most ${max} characters`);
22144
+ }
22145
+ if ((creating || Object.hasOwn(body, "title")) && (typeof body.title !== "string" || !body.title.trim())) fail3("title is required and cannot be blank");
22146
+ if (!creating && Object.hasOwn(body, "articleCategoryID")) fail3("articleCategoryID is read-only after creation");
22147
+ if (creating && String(reference(body.articleCategoryID, "articleCategoryID")) !== String(parent)) fail3("articleCategoryID must match parentId");
22148
+ if ((creating || Object.hasOwn(body, "publish")) && (typeof body.publish !== "number" || !Number.isSafeInteger(body.publish) || body.publish < -2147483648 || body.publish > 2147483647)) fail3("publish must be an int32 from current field metadata");
22149
+ if (Object.hasOwn(body, "isActive") && typeof body.isActive !== "boolean") fail3("isActive must be boolean");
22150
+ if (!creating && !Object.keys(body).length) fail3("update must contain a writable field");
21948
22151
  return body;
21949
22152
  }
21950
22153
  async function guardArticle(http, parentId, id, maxRetries) {
21951
22154
  const parent = articleParent(parentId);
21952
22155
  const target = id === void 0 ? void 0 : parseIdentifier(id, "id");
21953
- if (target !== void 0 && (target === 0 || !isAuditDecimalId(String(target)))) fail2("id must name an article within the signed 64-bit range");
22156
+ if (target !== void 0 && (target === 0 || !isAuditDecimalId(String(target)))) fail3("id must name an article within the signed 64-bit range");
21954
22157
  unwrapItem(await http.request({ method: "GET", path: `/V1.0/KnowledgeBaseCategories/${parent}`, operation: "knowledge_base_categories.get", maxRetries }), parent, "knowledge_base_categories.get", "article_category");
21955
22158
  if (target !== void 0) {
21956
22159
  return unwrapItem(await http.request({ method: "GET", path: `/V1.0/KnowledgeBaseCategories/${parent}/KnowledgeBaseArticles/${target}`, operation: "knowledge_base_articles.get", maxRetries }), target, "knowledge_base_articles.get", "article");
@@ -21959,7 +22162,7 @@ async function guardArticle(http, parentId, id, maxRetries) {
21959
22162
  }
21960
22163
  function assertArticlePublish(data, fields) {
21961
22164
  if (!Object.hasOwn(data, "publish")) return;
21962
- const unavailable = () => fail2("publish requires an unambiguous active value in current field metadata");
22165
+ const unavailable = () => fail3("publish requires an unambiguous active value in current field metadata");
21963
22166
  if (!Array.isArray(fields)) unavailable();
21964
22167
  const rows = fields.filter((field) => isRecord2(field) && field.name === "publish");
21965
22168
  if (rows.length !== 1 || rows[0].isPickList !== true || rows[0].isReadOnly !== false || !Array.isArray(rows[0].picklistValues)) unavailable();
@@ -21993,14 +22196,15 @@ var MutationBase = class extends MetaBase {
21993
22196
  return body;
21994
22197
  }
21995
22198
  /** `POST /V1.0/<E>` → `{ id }` (issue #13: a drifted 2xx runs the bounded marker recovery where the plan pins a marker field). */
21996
- async createGlobal(data, opts = {}) {
22199
+ async createGlobal(data, opts = {}, checkedBaseUrl) {
21997
22200
  const body = this.normalizeMutationBody(data);
21998
22201
  const res = await this.http.request({
21999
22202
  method: "POST",
22000
22203
  path: this.resourcePath,
22001
22204
  body,
22002
22205
  operation: `${this.config.key}.create`,
22003
- maxRetries: opts.maxRetries
22206
+ maxRetries: opts.maxRetries,
22207
+ ...checkedBaseUrl === void 0 ? {} : { checkedBaseUrl, maintenanceMaxWaitMs: 0 }
22004
22208
  });
22005
22209
  return this.unwrapCreateOperation(res, body, opts);
22006
22210
  }
@@ -22172,11 +22376,12 @@ var MutationBase = class extends MetaBase {
22172
22376
  const stored = parentId === void 0 ? await this.getGlobal(id, true, maxRetries, checkedBaseUrl) : this.config.attachmentGet === true ? await this.getScopedModel(parentId, id, true) : await this.getScopedRaw(parentId, id, true, maxRetries);
22173
22377
  const submitted = data;
22174
22378
  const persisted = stored;
22175
- if (this.config.key === "inventory_locations") {
22176
- if (!Object.hasOwn(persisted, "id")) throw new AutotaskConfigError("inventory_locations: persisted record requires its own id");
22379
+ const inventory = this.config.key === "inventory_locations" || this.config.key === "inventory_items";
22380
+ if (inventory) {
22381
+ if (!Object.hasOwn(persisted, "id")) throw new AutotaskConfigError(`${this.config.key}: persisted record requires its own id`);
22177
22382
  validateExactRecordResponse({ item: persisted }, "item", `${this.resourcePath}/${parseIdentifier(id, "id")}`, "GET", void 0, `${this.config.key}.get`);
22178
22383
  }
22179
- const notPersisted = this.config.key === "inventory_locations" ? Object.keys(submitted).filter((field) => !Object.hasOwn(persisted, field) || submitted[field] !== persisted[field]) : notPersistedFields(submitted, persisted);
22384
+ const notPersisted = inventory ? Object.keys(submitted).filter((field) => !Object.hasOwn(persisted, field) || submitted[field] !== persisted[field]) : notPersistedFields(submitted, persisted);
22180
22385
  return { ...result, notPersisted };
22181
22386
  } catch (err) {
22182
22387
  return { ...result, persistedCheckFailed: err instanceof AutotaskError ? err.code : `UNKNOWN (${err instanceof Error ? err.name : typeof err})` };
@@ -22563,7 +22768,7 @@ var MutationBase = class extends MetaBase {
22563
22768
  const method = scopedUpdate || partialCollection !== void 0 ? "PATCH" : "PUT";
22564
22769
  let current;
22565
22770
  try {
22566
- current = currentRecord ?? (parentId === void 0 ? await this.getGlobal(id, true, this.config.key === "knowledge_base_categories" || partialCollection !== void 0 ? opts.maxRetries : void 0) : this.config.attachmentGet ? await this.getScopedModel(parentId, id, true) : await this.getScopedRaw(parentId, id, true));
22771
+ 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));
22567
22772
  } catch (err) {
22568
22773
  if (err instanceof NotFoundError) {
22569
22774
  const reasons = EMPTY_REASON_STAMPS[this.config.key];
@@ -22589,7 +22794,7 @@ var MutationBase = class extends MetaBase {
22589
22794
  throw err;
22590
22795
  }
22591
22796
  checks.push({ name: "current-record-exists", ok: true });
22592
- partialCollection?.checkCurrent(current);
22797
+ if (partialCollection !== void 0) await partialCollection.checkCurrent(current);
22593
22798
  if (this.staleObjectCheck(current, opts, operation)) {
22594
22799
  checks.push({ name: "stale-check", ok: true });
22595
22800
  }
@@ -22671,34 +22876,34 @@ var BaseResource = class extends MutationBase {
22671
22876
  };
22672
22877
 
22673
22878
  // src/resources/special/taskPredecessors.ts
22674
- function fail3(detail) {
22879
+ function fail4(detail) {
22675
22880
  throw new AutotaskConfigError(`task_predecessors: ${detail}`);
22676
22881
  }
22677
22882
  function numeric(value, field) {
22678
- if (typeof value !== "number" || !Number.isSafeInteger(value) || value <= 0) fail3(`${field} must be a positive numeric identifier`);
22883
+ if (typeof value !== "number" || !Number.isSafeInteger(value) || value <= 0) fail4(`${field} must be a positive numeric identifier`);
22679
22884
  return value;
22680
22885
  }
22681
22886
  function predecessorParent(value) {
22682
22887
  const parent = parseIdentifier(value, "parentId");
22683
- if (parent === 0) fail3("parentId must name a successor task");
22888
+ if (parent === 0) fail4("parentId must name a successor task");
22684
22889
  return parent;
22685
22890
  }
22686
22891
  function assertPredecessorBinding(value, parentId, id) {
22687
- if (!isRecord2(value)) fail3("the returned record must establish id and successorTaskID parent");
22688
- if (String(parseIdentifier(value.id, "record.id")) !== String(parseIdentifier(id, "id")) || String(parseIdentifier(value.successorTaskID, "record.successorTaskID")) !== String(predecessorParent(parentId))) fail3("the returned record must match id and successorTaskID parent");
22892
+ if (!isRecord2(value)) fail4("the returned record must establish id and successorTaskID parent");
22893
+ if (String(parseIdentifier(value.id, "record.id")) !== String(parseIdentifier(id, "id")) || String(parseIdentifier(value.successorTaskID, "record.successorTaskID")) !== String(predecessorParent(parentId))) fail4("the returned record must match id and successorTaskID parent");
22689
22894
  }
22690
22895
  function admitTaskPredecessor(data, parentId, creating) {
22691
22896
  const parent = predecessorParent(parentId);
22692
- if (!isRecord2(data) || ![Object.prototype, null].includes(Object.getPrototypeOf(data))) fail3("data must be a plain record");
22897
+ if (!isRecord2(data) || ![Object.prototype, null].includes(Object.getPrototypeOf(data))) fail4("data must be a plain record");
22693
22898
  const payload = { ...data };
22694
22899
  const allowed = creating ? ["predecessorTaskID", "successorTaskID", "lagDays"] : ["lagDays"];
22695
- if (Object.keys(payload).some((key) => !allowed.includes(key))) fail3(creating ? "only predecessorTaskID, successorTaskID and lagDays are writable on create" : "only lagDays can be updated");
22696
- if ((!creating || payload.lagDays !== void 0) && (typeof payload.lagDays !== "number" || !Number.isInteger(payload.lagDays) || payload.lagDays < -2147483648 || payload.lagDays > 2147483647)) fail3("lagDays must be an int32 integer");
22900
+ if (Object.keys(payload).some((key) => !allowed.includes(key))) fail4(creating ? "only predecessorTaskID, successorTaskID and lagDays are writable on create" : "only lagDays can be updated");
22901
+ if ((!creating || payload.lagDays !== void 0) && (typeof payload.lagDays !== "number" || !Number.isInteger(payload.lagDays) || payload.lagDays < -2147483648 || payload.lagDays > 2147483647)) fail4("lagDays must be an int32 integer");
22697
22902
  if (creating) {
22698
22903
  const successor = numeric(payload.successorTaskID, "successorTaskID");
22699
22904
  const predecessor = numeric(payload.predecessorTaskID, "predecessorTaskID");
22700
- if (String(successor) !== String(parent)) fail3("successorTaskID must match parentId");
22701
- if (predecessor === successor) fail3("predecessorTaskID and successorTaskID must be distinct");
22905
+ if (String(successor) !== String(parent)) fail4("successorTaskID must match parentId");
22906
+ if (predecessor === successor) fail4("predecessorTaskID and successorTaskID must be distinct");
22702
22907
  }
22703
22908
  return payload;
22704
22909
  }
@@ -22707,50 +22912,50 @@ async function guardTaskPredecessor(http, parentId, id, data) {
22707
22912
  let row = data;
22708
22913
  if (id !== void 0) {
22709
22914
  const target = parseIdentifier(id, "id");
22710
- if (target === 0) fail3("id must name a predecessor relationship");
22915
+ if (target === 0) fail4("id must name a predecessor relationship");
22711
22916
  row = unwrapItem(await http.request({ method: "GET", path: `/V1.0/Tasks/${parent}/Predecessors/${target}`, operation: "task_predecessors.get" }), target, "task_predecessors.get", "task_predecessor");
22712
22917
  assertPredecessorBinding(row, parent, target);
22713
22918
  }
22714
22919
  const predecessor = numeric(row?.predecessorTaskID, "predecessorTaskID");
22715
22920
  const successor = numeric(row?.successorTaskID, "successorTaskID");
22716
- if (predecessor === successor) fail3("predecessorTaskID and successorTaskID must be distinct");
22921
+ if (predecessor === successor) fail4("predecessorTaskID and successorTaskID must be distinct");
22717
22922
  const projects = [];
22718
22923
  for (const taskId of [predecessor, successor]) {
22719
22924
  const task = unwrapItem(await http.request({ method: "GET", path: `/V1.0/Tasks/${taskId}`, operation: "tasks.get" }), taskId, "tasks.get", "task");
22720
- if (String(parseIdentifier(task.id, "task.id")) !== String(taskId)) fail3("the returned task must match its requested id");
22925
+ if (String(parseIdentifier(task.id, "task.id")) !== String(taskId)) fail4("the returned task must match its requested id");
22721
22926
  projects.push(numeric(task.projectID, "task.projectID"));
22722
22927
  }
22723
- if (projects[0] !== projects[1]) fail3("predecessor and successor tasks must belong to the same project");
22928
+ if (projects[0] !== projects[1]) fail4("predecessor and successor tasks must belong to the same project");
22724
22929
  }
22725
22930
 
22726
22931
  // src/resources/special/taskNotes.ts
22727
22932
  var WRITABLE = /* @__PURE__ */ new Set(["id", "itemId", "createdByContactID", "description", "noteType", "publish", "taskID", "title"]);
22728
22933
  function admitTaskNote(data, parentId, creating) {
22729
22934
  const parent = parseIdentifier(parentId, "parentId");
22730
- const fail4 = (message) => {
22935
+ const fail5 = (message) => {
22731
22936
  throw new AutotaskConfigError(`task_notes: ${message}`);
22732
22937
  };
22733
- if (data === null || typeof data !== "object" || Array.isArray(data)) fail4("data must be a record");
22938
+ if (data === null || typeof data !== "object" || Array.isArray(data)) fail5("data must be a record");
22734
22939
  const body = data;
22735
- for (const key of Object.keys(body)) if (!WRITABLE.has(key)) fail4(`${key} is not a writable TaskNotes field`);
22940
+ for (const key of Object.keys(body)) if (!WRITABLE.has(key)) fail5(`${key} is not a writable TaskNotes field`);
22736
22941
  for (const [field, maximum] of [["description", 3200], ["title", 250]]) {
22737
22942
  const value = body[field];
22738
- if (value !== void 0 && (typeof value !== "string" || value.length > maximum)) fail4(`${field} must be a string of at most ${maximum} characters`);
22943
+ if (value !== void 0 && (typeof value !== "string" || value.length > maximum)) fail5(`${field} must be a string of at most ${maximum} characters`);
22739
22944
  }
22740
- if (creating && (typeof body.description !== "string" || body.description.trim() === "")) fail4("description is required");
22945
+ if (creating && (typeof body.description !== "string" || body.description.trim() === "")) fail5("description is required");
22741
22946
  for (const field of ["noteType", "publish"]) {
22742
22947
  const value = body[field];
22743
- if ((creating || value !== void 0) && (typeof value !== "number" || !Number.isSafeInteger(value))) fail4(`${field} must be an integer from the current field metadata`);
22948
+ if ((creating || value !== void 0) && (typeof value !== "number" || !Number.isSafeInteger(value))) fail5(`${field} must be an integer from the current field metadata`);
22744
22949
  }
22745
- if (creating && body.taskID === void 0) fail4("taskID is required in the create body and must match parentId");
22950
+ if (creating && body.taskID === void 0) fail5("taskID is required in the create body and must match parentId");
22746
22951
  for (const field of ["createdByContactID", "taskID"]) {
22747
22952
  if (body[field] !== void 0) {
22748
- if (typeof body[field] !== "number") fail4(`${field} must be a numeric identifier`);
22953
+ if (typeof body[field] !== "number") fail5(`${field} must be a numeric identifier`);
22749
22954
  const id = parseIdentifier(body[field], field);
22750
- if (field === "taskID" && String(id) !== String(parent)) fail4("taskID must match the parentId path argument");
22955
+ if (field === "taskID" && String(id) !== String(parent)) fail5("taskID must match the parentId path argument");
22751
22956
  }
22752
22957
  }
22753
- if (!creating && !Object.keys(body).some((key) => key !== "id" && key !== "itemId")) fail4("update must contain a writable field");
22958
+ if (!creating && !Object.keys(body).some((key) => key !== "id" && key !== "itemId")) fail5("update must contain a writable field");
22754
22959
  }
22755
22960
 
22756
22961
  // src/operations/invoke/fieldSuggest.ts
@@ -22885,8 +23090,8 @@ function collectFilterFieldNames(conditions, resourceKey, operation = `${resourc
22885
23090
  continue;
22886
23091
  }
22887
23092
  if (resourceKey !== void 0) {
22888
- const own = normalizeOwnField(resourceKey, cond.field);
22889
- if (own !== cond.field) out.push(own);
23093
+ const own2 = normalizeOwnField(resourceKey, cond.field);
23094
+ if (own2 !== cond.field) out.push(own2);
22890
23095
  }
22891
23096
  }
22892
23097
  }
@@ -22978,6 +23183,7 @@ async function validateQueryFieldNames(record, holder, args) {
22978
23183
  let filterNames;
22979
23184
  if (bag["filter"] !== void 0) {
22980
23185
  const conditions = normalizedConditions(bag["filter"]);
23186
+ assertSupportedUdfConditions(conditions, record.id);
22981
23187
  filterNames = collectFilterFieldNames(conditions ?? [], record.resource, record.id);
22982
23188
  }
22983
23189
  if (fieldCheck === false) return;
@@ -23020,38 +23226,38 @@ function isBase64(value) {
23020
23226
  }
23021
23227
  function admitTaskAttachment(data, parentId) {
23022
23228
  const parent = parseIdentifier(parentId, "parentId");
23023
- const fail4 = (message) => {
23229
+ const fail5 = (message) => {
23024
23230
  throw new AutotaskConfigError(`task_attachments: ${message}`);
23025
23231
  };
23026
- if (data === null || typeof data !== "object" || ![Object.prototype, null].includes(Object.getPrototypeOf(data))) fail4("data must be a plain record");
23232
+ if (data === null || typeof data !== "object" || ![Object.prototype, null].includes(Object.getPrototypeOf(data))) fail5("data must be a plain record");
23027
23233
  const body = data;
23028
- for (const field of Object.keys(body)) if (!WRITABLE2.has(field)) fail4(`${field} is not a supported create field`);
23234
+ for (const field of Object.keys(body)) if (!WRITABLE2.has(field)) fail5(`${field} is not a supported create field`);
23029
23235
  for (const field of ["attachmentType", "fullPath", "title"]) {
23030
- if (typeof body[field] !== "string" || body[field].trim() === "") fail4(`${field} is required and must be a non-empty string`);
23236
+ if (typeof body[field] !== "string" || body[field].trim() === "") fail5(`${field} is required and must be a non-empty string`);
23031
23237
  }
23032
- if (typeof body.publish !== "number" || !Number.isSafeInteger(body.publish)) fail4("publish must be an integer from current field metadata");
23238
+ if (typeof body.publish !== "number" || !Number.isSafeInteger(body.publish)) fail5("publish must be an integer from current field metadata");
23033
23239
  for (const field of ["data", "contentType"]) {
23034
- if (body[field] !== void 0 && typeof body[field] !== "string") fail4(`${field} must be a string`);
23240
+ if (body[field] !== void 0 && typeof body[field] !== "string") fail5(`${field} must be a string`);
23035
23241
  }
23036
23242
  if (body.attachmentType === "FILE_ATTACHMENT") {
23037
- if (typeof body.data !== "string" || body.data === "") return fail4("FILE_ATTACHMENT requires non-empty base64 data");
23038
- if (!isBase64(body.data)) fail4("FILE_ATTACHMENT data must be base64 encoded");
23243
+ if (typeof body.data !== "string" || body.data === "") return fail5("FILE_ATTACHMENT requires non-empty base64 data");
23244
+ if (!isBase64(body.data)) fail5("FILE_ATTACHMENT data must be base64 encoded");
23039
23245
  }
23040
23246
  if (body.taskID !== void 0) {
23041
- if (typeof body.taskID !== "number") fail4("taskID must be a numeric identifier");
23042
- if (String(parseIdentifier(body.taskID, "taskID")) !== String(parent)) fail4("taskID must match the parentId path argument");
23247
+ if (typeof body.taskID !== "number") fail5("taskID must be a numeric identifier");
23248
+ if (String(parseIdentifier(body.taskID, "taskID")) !== String(parent)) fail5("taskID must match the parentId path argument");
23043
23249
  }
23044
23250
  if (body.parentAttachmentID !== void 0) {
23045
- if (typeof body.parentAttachmentID !== "number") fail4("parentAttachmentID must be a numeric identifier");
23251
+ if (typeof body.parentAttachmentID !== "number") fail5("parentAttachmentID must be a numeric identifier");
23046
23252
  parseIdentifier(body.parentAttachmentID, "parentAttachmentID");
23047
23253
  }
23048
23254
  }
23049
23255
  function admitFileAttachment(resource, data, parentId) {
23050
23256
  parseIdentifier(parentId, "parentId");
23051
- const fail4 = (message) => {
23257
+ const fail5 = (message) => {
23052
23258
  throw new AutotaskConfigError(`${resource}: ${message}`);
23053
23259
  };
23054
- if (data === null || typeof data !== "object" || ![Object.prototype, null].includes(Object.getPrototypeOf(data))) fail4("data must be a plain record");
23260
+ if (data === null || typeof data !== "object" || ![Object.prototype, null].includes(Object.getPrototypeOf(data))) fail5("data must be a plain record");
23055
23261
  const body = data;
23056
23262
  const reference2 = {
23057
23263
  project_attachments: void 0,
@@ -23064,20 +23270,20 @@ function admitFileAttachment(resource, data, parentId) {
23064
23270
  configuration_item_attachments: "parentAttachmentID",
23065
23271
  configuration_item_note_attachments: void 0
23066
23272
  }[resource];
23067
- for (const field of Object.keys(body)) if (!FILE_WRITABLE.has(field) && field !== reference2) fail4(`${field} is not a supported create field`);
23068
- if (body.attachmentType !== "FILE_ATTACHMENT") fail4("attachmentType must explicitly be FILE_ATTACHMENT; other attachment types are unsupported");
23273
+ for (const field of Object.keys(body)) if (!FILE_WRITABLE.has(field) && field !== reference2) fail5(`${field} is not a supported create field`);
23274
+ if (body.attachmentType !== "FILE_ATTACHMENT") fail5("attachmentType must explicitly be FILE_ATTACHMENT; other attachment types are unsupported");
23069
23275
  const maxLength = resource === "project_attachments" ? void 0 : 255;
23070
23276
  for (const field of ["fullPath", "title"]) {
23071
23277
  const value = body[field];
23072
23278
  const requirement = `${field} is required and must be a nonblank string${maxLength === void 0 ? "" : ` of at most ${maxLength} characters`}`;
23073
- if (typeof value !== "string" || value.trim() === "") return fail4(requirement);
23074
- if (maxLength !== void 0 && value.length > maxLength) fail4(requirement);
23279
+ if (typeof value !== "string" || value.trim() === "") return fail5(requirement);
23280
+ if (maxLength !== void 0 && value.length > maxLength) fail5(requirement);
23075
23281
  }
23076
- if (typeof body.publish !== "number" || !Number.isSafeInteger(body.publish)) fail4("publish must be an integer from current field metadata");
23077
- if (typeof body.data !== "string" || !isBase64(body.data)) fail4("FILE_ATTACHMENT requires nonempty base64 data");
23282
+ if (typeof body.publish !== "number" || !Number.isSafeInteger(body.publish)) fail5("publish must be an integer from current field metadata");
23283
+ if (typeof body.data !== "string" || !isBase64(body.data)) fail5("FILE_ATTACHMENT requires nonempty base64 data");
23078
23284
  if (reference2 !== void 0 && body[reference2] !== void 0) {
23079
- if (typeof body[reference2] !== "number") fail4(`${reference2} must be a numeric identifier`);
23080
- if (parseIdentifier(body[reference2], reference2) === 0) fail4(`${reference2} must be positive`);
23285
+ if (typeof body[reference2] !== "number") fail5(`${reference2} must be a numeric identifier`);
23286
+ if (parseIdentifier(body[reference2], reference2) === 0) fail5(`${reference2} must be positive`);
23081
23287
  }
23082
23288
  }
23083
23289
  function admitScopedAttachmentQuery(resource, params) {
@@ -23936,6 +24142,16 @@ var SIMPLE_RESOURCES = [
23936
24142
  helpers: { search: false, resolve: false, getContext: false, createIfNotExists: false, attachToDocument: false, findBy: [] },
23937
24143
  opForms: { get: "global" }
23938
24144
  },
24145
+ {
24146
+ key: "inventory_items",
24147
+ accessor: "inventoryItems",
24148
+ resourcePath: "/V1.0/InventoryItems",
24149
+ deletable: false,
24150
+ udfCapable: false,
24151
+ ops: { query: true, queryAll: false, count: true, get: true, create: true, update: true, delete: false, getEntityInfo: true, getFieldInfo: true, getUdfInfo: true },
24152
+ helpers: { search: false, resolve: false, getContext: false, createIfNotExists: false, attachToDocument: false, findBy: [] },
24153
+ opForms: { get: "global", create: "global", update: "global" }
24154
+ },
23939
24155
  {
23940
24156
  key: "inventory_locations",
23941
24157
  accessor: "inventoryLocations",
@@ -24851,7 +25067,7 @@ var GenericResource = class extends BaseResource {
24851
25067
  if (["company_attachments", "company_note_attachments", "configuration_item_attachments", "configuration_item_note_attachments", "contract_note_attachments", "expense_report_attachments", "project_attachments", "project_note_attachments", "resource_attachments", "sales_order_attachments", "task_attachments", "task_note_attachments"].includes(config.key)) this.getUdfInfo = async () => {
24852
25068
  throw new OperationNotSupportedError(config.key, "getUdfInfo");
24853
25069
  };
24854
- if (config.ops?.create === false || isScopedAttachmentResource(config.key) || ["company_attachments", "task_predecessors", "knowledge_base_articles", "inventory_locations"].includes(config.key)) this.createIfNotExists = async () => {
25070
+ if (config.ops?.create === false || isScopedAttachmentResource(config.key) || ["company_attachments", "task_predecessors", "knowledge_base_articles", "inventory_locations", "inventory_items"].includes(config.key)) this.createIfNotExists = async () => {
24855
25071
  throw new OperationNotSupportedError(config.key, "createIfNotExists");
24856
25072
  };
24857
25073
  if (config.key === "knowledge_base_categories") {
@@ -24966,6 +25182,20 @@ var GenericResource = class extends BaseResource {
24966
25182
  return this.createScopedRaw(parentId, data2, opts2);
24967
25183
  }
24968
25184
  if (this.config.opForms?.create === "scoped") throw new OperationNotSupportedError(this.config.key, "create");
25185
+ if (this.config.key === "inventory_items") {
25186
+ const body = admitInventoryItem(a, true);
25187
+ const opts2 = snapshotInventoryItemOptions(b);
25188
+ const checkedBaseUrl = this.http.baseUrl;
25189
+ try {
25190
+ await guardInventoryItemCreate(this.http, body, checkedBaseUrl, opts2.maxRetries);
25191
+ } catch (error) {
25192
+ if (error instanceof AutotaskError) Object.assign(error, { notSent: true });
25193
+ throw error;
25194
+ }
25195
+ if (opts2.dryRun === true) return this.runCreateDryRun(body);
25196
+ const result = await this.createGlobal(body, opts2, checkedBaseUrl);
25197
+ return this.withPersistedCheck(result, body, opts2, result.id, void 0, checkedBaseUrl);
25198
+ }
24969
25199
  const data = this.config.key === "knowledge_base_categories" ? admitKnowledgeBaseCategory(a, true) : this.config.key === "inventory_locations" ? admitInventoryLocation(a, true) : a;
24970
25200
  const supplied = b;
24971
25201
  const opts = ["knowledge_base_categories", "inventory_locations"].includes(this.config.key) ? snapshotMutationOptions(supplied) : supplied ?? {};
@@ -24994,6 +25224,21 @@ var GenericResource = class extends BaseResource {
24994
25224
  return this.updateScopedRaw(parentId, id2, data2, opts2);
24995
25225
  }
24996
25226
  if (this.config.opForms?.update === "scoped") throw new OperationNotSupportedError(this.config.key, "update");
25227
+ if (this.config.key === "inventory_items") {
25228
+ const id2 = inventoryItemId(a);
25229
+ const body = admitInventoryItem(b, false);
25230
+ const opts2 = snapshotInventoryItemOptions(c);
25231
+ const checkedBaseUrl = this.http.baseUrl;
25232
+ const checkCurrent = (current) => checkInventoryItemCurrent(this.http, body, current, id2, checkedBaseUrl, opts2.maxRetries);
25233
+ if (opts2.dryRun === true) return this.runUpdateDryRun(id2, body, opts2, void 0, void 0, { checkCurrent, checkedBaseUrl });
25234
+ try {
25235
+ await checkCurrent(await this.getGlobal(id2, true, opts2.maxRetries, checkedBaseUrl));
25236
+ } catch (error) {
25237
+ if (error instanceof AutotaskError) Object.assign(error, { notSent: true });
25238
+ throw error;
25239
+ }
25240
+ return this.updateGlobal(id2, body, opts2, "PATCH", checkedBaseUrl);
25241
+ }
24997
25242
  const category = this.config.key === "knowledge_base_categories";
24998
25243
  const location = this.config.key === "inventory_locations";
24999
25244
  const id = category || location ? parseIdentifier(a, "id") : a;
@@ -26936,6 +27181,7 @@ async function aggregate(client, operation, filter, opts = {}) {
26936
27181
  const labelled = !label || v.groupBy.length === 0 ? void 0 : await labelRows(client, v.resourceKey, top.map((g) => g.key));
26937
27182
  const result = {
26938
27183
  mode: v.groupBy.length > 0 ? "group" : "sum",
27184
+ ...v.resourceKey === "inventory_items" ? { resource: v.resourceKey } : {},
26939
27185
  groups: top.map((g, i) => ({ key: labelled?.rows[i] ?? g.key, count: g.count, ...g.sums !== void 0 ? { sums: g.sums } : {} })),
26940
27186
  totalGroups: sorted.length,
26941
27187
  groupsTruncated: sorted.length > top.length,
@@ -27335,15 +27581,32 @@ async function sanitiseResult(client, result, operation) {
27335
27581
  { suggestedAction: "Pass the operation key the result came from \u2014 the registry id, not the resource key." }
27336
27582
  );
27337
27583
  }
27338
- const record = (await operationIndex()).get(operation);
27584
+ const records = await operationIndex();
27585
+ const record = records.get(operation);
27339
27586
  if (record === void 0) {
27340
27587
  throw new AutotaskConfigError(
27341
27588
  `sanitiseResult: unknown operation "${operation.slice(0, 60)}" \u2014 it is not in the capability registry`,
27342
27589
  { operation, suggestedAction: "List the registry (the ./capabilities subpath) for the exact operation key." }
27343
27590
  );
27344
27591
  }
27345
- const fields = record.metadata?.untrustedFields;
27346
- return deepMarkUntrusted(result, Array.isArray(fields) ? fields : []);
27592
+ const names = record.metadata.untrustedFields;
27593
+ const fields = Array.isArray(names) ? names : [];
27594
+ const inventoryAggregate = operation === "operations.aggregate" && result.resource === "inventory_items";
27595
+ const projected = deepMarkUntrusted(result, inventoryAggregate ? [...fields, "referenceNumber"] : fields);
27596
+ if (operation === "operations.searchAcrossResources") return wrapReferenceRows(projected, "matches");
27597
+ if (operation === "operations.fetchByIds") return wrapReferenceRows(projected, "value");
27598
+ if (operation === "operations.resolveAny") {
27599
+ const wrapped = wrapReferenceRows(projected, "value");
27600
+ return isRecord2(wrapped.contains) ? { ...wrapped, contains: wrapReferenceRows(wrapped.contains, "matches") } : wrapped;
27601
+ }
27602
+ return projected;
27603
+ }
27604
+ function wrapReferenceRows(result, field) {
27605
+ if (!Array.isArray(result.results)) return result;
27606
+ return { ...result, results: result.results.map((row) => {
27607
+ if (!isRecord2(row) || typeof row.resource !== "string" || !Object.hasOwn(row, field) || !row.resource.split("_").every(Boolean) || camelKey(row.resource) !== "inventoryItems") return row;
27608
+ return { ...row, [field]: deepMarkUntrusted(row[field], ["referenceNumber"]) };
27609
+ }) };
27347
27610
  }
27348
27611
 
27349
27612
  // src/resources/special/invoices.ts
@@ -28746,18 +29009,18 @@ async function fetchExpenses(ctx, join, entries) {
28746
29009
  const gaps = [...task.gaps];
28747
29010
  const timeTruncated = ctx.truncatedMonths["timeEntries"];
28748
29011
  if (timeTruncated !== void 0 && timeTruncated.length > 0) gaps.push(`time entries truncated in ${timeTruncated.join(", ")}, so a no-contract ticket or task their missing rows reference is not joined`);
28749
- const own = [
29012
+ const own2 = [
28750
29013
  ...tasks.ids.length > 0 ? [{ field: "taskID", op: "in", value: tasks.ids }] : [],
28751
29014
  ...task.projectIds.length > 0 ? [{ field: "projectID", op: "in", value: task.projectIds }] : []
28752
29015
  ];
28753
29016
  const orOf = (keys) => [keys.length === 1 ? keys[0] : { op: "or", items: keys }, ...ctx.windowOn("expenseDate")];
28754
- const expCond = orOf([{ field: "ticketID", op: "exist" }, ...own]);
29017
+ const expCond = orOf([{ field: "ticketID", op: "exist" }, ...own2]);
28755
29018
  const shared = ctx.sharedExpenses;
28756
29019
  let raw;
28757
- if (shared && own.length === 0) {
29020
+ if (shared && own2.length === 0) {
28758
29021
  raw = { items: [], capped: false, hasMore: false };
28759
29022
  } else {
28760
- const read = await ctx.windowedPart("expenses", "expense_items", "/V1.0/ExpenseItems/query", shared ? orOf(own) : expCond, EXPENSE_FIELDS, "expenseDate", EXPENSE_PAGE);
29023
+ const read = await ctx.windowedPart("expenses", "expense_items", "/V1.0/ExpenseItems/query", shared ? orOf(own2) : expCond, EXPENSE_FIELDS, "expenseDate", EXPENSE_PAGE);
28761
29024
  raw = read.part;
28762
29025
  raw.items = read.rows;
28763
29026
  }
@@ -29658,16 +29921,16 @@ function latchingHttp(raw, spend) {
29658
29921
  }
29659
29922
  };
29660
29923
  observeRecordReadFailures(http, latch);
29661
- const fail4 = (err) => {
29924
+ const fail5 = (err) => {
29662
29925
  latch(err);
29663
29926
  throw err;
29664
29927
  };
29665
29928
  http.request = (o) => {
29666
29929
  if (fatal) throw fatal;
29667
29930
  try {
29668
- return counted.request({ ...o, signal: o.signal ?? signal }).catch(fail4);
29931
+ return counted.request({ ...o, signal: o.signal ?? signal }).catch(fail5);
29669
29932
  } catch (err) {
29670
- return fail4(err);
29933
+ return fail5(err);
29671
29934
  }
29672
29935
  };
29673
29936
  return { http, fatal: () => fatal, signal };