node-autotask 0.39.4 → 0.41.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 (44) hide show
  1. package/ARCHITECTURE.md +6 -2
  2. package/CHANGELOG.md +33 -0
  3. package/MCP_TOOL_CATALOG.json +10 -32
  4. package/MCP_TOOL_MANIFEST.md +12 -13
  5. package/N8N_MCP_MANIFEST.json +5 -44
  6. package/N8N_MCP_MANIFEST.md +7 -8
  7. package/README.md +29 -37
  8. package/capabilities.json +1346 -1535
  9. package/dist/base-CVx2VMSj.d.cts +103 -0
  10. package/dist/base-CVx2VMSj.d.ts +103 -0
  11. package/dist/capabilities.cjs +2 -2
  12. package/dist/capabilities.js +1 -1
  13. package/dist/{chunk-SGKGNJEI.cjs → chunk-DKAD7MOV.cjs} +771 -1835
  14. package/dist/{chunk-DJCRQLQE.cjs → chunk-DXEBPK55.cjs} +287 -292
  15. package/dist/{chunk-GHRB46YN.js → chunk-LR6FDJI3.js} +614 -1678
  16. package/dist/{chunk-VR6RYXTD.cjs → chunk-MJ6J74F3.cjs} +1345 -1534
  17. package/dist/{chunk-JBQ55HYG.js → chunk-P5655PGY.js} +2 -2
  18. package/dist/{chunk-DBLXPY4B.js → chunk-TCND5PFF.js} +4 -9
  19. package/dist/{chunk-H4S4KSXX.cjs → chunk-YAHFPOQF.cjs} +143 -143
  20. package/dist/{chunk-GDSCYY2G.js → chunk-ZVSSAULC.js} +1345 -1534
  21. package/dist/{index-DkZVRMeW.d.ts → index-CqO1HNHl.d.cts} +125 -851
  22. package/dist/{index-DkZVRMeW.d.cts → index-CqO1HNHl.d.ts} +125 -851
  23. package/dist/index.cjs +23 -51
  24. package/dist/index.d.cts +103 -102
  25. package/dist/index.d.ts +103 -102
  26. package/dist/index.js +19 -47
  27. package/dist/operations/index.cjs +178 -178
  28. package/dist/operations/index.d.cts +5 -4
  29. package/dist/operations/index.d.ts +5 -4
  30. package/dist/operations/index.js +3 -3
  31. package/dist/pool.cjs +17 -60
  32. package/dist/pool.d.cts +5 -13
  33. package/dist/pool.d.ts +5 -13
  34. package/dist/pool.js +13 -56
  35. package/dist/resources/index.cjs +4 -4
  36. package/dist/resources/index.d.cts +1 -1
  37. package/dist/resources/index.d.ts +1 -1
  38. package/dist/resources/index.js +3 -3
  39. package/dist/types/index.d.cts +1 -1
  40. package/dist/types/index.d.ts +1 -1
  41. package/docs/API.md +138 -340
  42. package/docs/N8N-ADAPTER.md +7 -7
  43. package/examples/mcp-server-http.ts +18 -18
  44. package/package.json +1 -1
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  CAPABILITIES
3
- } from "./chunk-GDSCYY2G.js";
3
+ } from "./chunk-ZVSSAULC.js";
4
4
  import {
5
5
  wrapUntrusted
6
6
  } from "./chunk-5VHSLJMR.js";
@@ -181,14 +181,14 @@ var EmptyResponseError = class extends AutotaskError {
181
181
  this.name = "EmptyResponseError";
182
182
  }
183
183
  };
184
- var CircuitBreakerError = class extends AutotaskError {
185
- /** Seconds remaining in the open period (absent when the half-open probe budget is in flight). */
184
+ var MaintenanceError = class extends AutotaskError {
185
+ /** Seconds until the next probe slot. */
186
186
  retryAfter;
187
- /** True when the call was refused locally (the circuit is open) and never sent. */
187
+ /** True on a local refusal (the call was never sent); undefined when the call received the page. */
188
188
  notSent;
189
189
  constructor(message, options = {}) {
190
- super(message, { code: "CIRCUIT_BREAKER_OPEN", category: "policy", retryable: true, ...options });
191
- this.name = "CircuitBreakerError";
190
+ super(message, { code: "MAINTENANCE", category: "server", retryable: true, ...options });
191
+ this.name = "MaintenanceError";
192
192
  }
193
193
  };
194
194
  var HostPolicyDeniedError = class extends AutotaskError {
@@ -588,53 +588,36 @@ var MoveRefusedError = class extends AutotaskError {
588
588
 
589
589
  // src/cache.ts
590
590
  var READ_CACHE_MAX_ENTRIES = 4096;
591
- var ReadCache = class {
592
- /** The configured TTL in ms (the fallback for resources without an override). */
591
+ var REFERENCE_TTL_MS = 36e5;
592
+ var REFERENCE_ENTITIES = ["BillingCodes", "Countries", "Departments", "Phases", "Roles", "Services"];
593
+ var FIELD_CACHE_KINDS = ["info", "fields", "udf"];
594
+ function fieldKey(resourceKey, kind) {
595
+ return `${resourceKey}:${kind}`;
596
+ }
597
+ function readTtlFor(key, ttlMs) {
598
+ const entity = key.split("\0")[0].split("/").at(-2);
599
+ return entity !== void 0 && REFERENCE_ENTITIES.includes(entity) ? Math.max(ttlMs, REFERENCE_TTL_MS) : ttlMs;
600
+ }
601
+ var TtlCache = class {
593
602
  ttlMs;
594
- /** The per-resource TTL overrides (issue #32; absent = every resource uses `ttlMs`). */
595
- perResourceTtlMs;
603
+ maxEntries;
604
+ ttlFor;
596
605
  store = /* @__PURE__ */ new Map();
606
+ inflightMap = /* @__PURE__ */ new Map();
597
607
  epochCounter = 0;
598
- constructor(ttlMs, perResourceTtlMs) {
608
+ constructor(ttlMs, options = {}) {
599
609
  if (!Number.isInteger(ttlMs) || ttlMs <= 0) {
600
- throw new AutotaskConfigError(`cache.ttlMs must be a positive integer (got ${ttlMs})`);
610
+ throw new AutotaskConfigError(`cache ttlMs must be a positive integer (got ${String(ttlMs)})`);
601
611
  }
602
- if (perResourceTtlMs !== void 0) {
603
- if (perResourceTtlMs === null || typeof perResourceTtlMs !== "object" || Array.isArray(perResourceTtlMs)) {
604
- throw new AutotaskConfigError(
605
- `cache.perResourceTtlMs must be an object of resource key -> ms (got ${String(perResourceTtlMs)})`
606
- );
607
- }
608
- for (const [key, value] of Object.entries(perResourceTtlMs)) {
609
- if (key === "") {
610
- throw new AutotaskConfigError("cache.perResourceTtlMs keys must be non-empty resource keys");
611
- }
612
- if (!Number.isInteger(value) || value <= 0) {
613
- throw new AutotaskConfigError(
614
- `cache.perResourceTtlMs.${key} must be a positive integer (got ${String(value)})`
615
- );
616
- }
617
- }
612
+ const maxEntries = options.maxEntries ?? READ_CACHE_MAX_ENTRIES;
613
+ if (!Number.isInteger(maxEntries) || maxEntries <= 0) {
614
+ throw new AutotaskConfigError(`cache maxEntries must be a positive integer (got ${String(maxEntries)})`);
618
615
  }
619
616
  this.ttlMs = ttlMs;
620
- this.perResourceTtlMs = perResourceTtlMs;
621
- }
622
- /**
623
- * The TTL (ms) for a resource plan key: the `perResourceTtlMs` override
624
- * when the map is present and names the resource, else the base
625
- * `ttlMs` (absent map, absent key, and `undefined` all fall back).
626
- */
627
- ttlFor(resource) {
628
- if (resource !== void 0 && this.perResourceTtlMs !== void 0) {
629
- const override = this.perResourceTtlMs[resource];
630
- if (override !== void 0) return override;
631
- }
632
- return this.ttlMs;
617
+ this.maxEntries = maxEntries;
618
+ this.ttlFor = options.ttlFor ?? (() => ttlMs);
633
619
  }
634
- /**
635
- * Read-through lookup: the live entry's value, or `undefined` (absent OR
636
- * expired — an expired entry is purged lazily on this read).
637
- */
620
+ /** The live value (a copy), or `undefined` when absent or expired. */
638
621
  get(key) {
639
622
  const entry = this.store.get(key);
640
623
  if (entry === void 0) return void 0;
@@ -644,19 +627,46 @@ var ReadCache = class {
644
627
  }
645
628
  return structuredClone(entry.value);
646
629
  }
647
- /** Store a successful read payload under `key`, live for `ttlFor(resource)`:
648
- * the per-resource override (issue #32) when named, else `ttlMs`.
649
- * `epoch` is the invalidation epoch the caller captured BEFORE its wire
650
- * read: a read that straddled a `clear()` (a write) is dropped, never
651
- * re-stored with its pre-write body. */
652
- set(key, value, resource, epoch = this.epochCounter) {
630
+ /** Store `value` under `key`. `epoch` is the value the caller read BEFORE its
631
+ * wire request: a read that straddled a `clear()` (a write) is dropped. */
632
+ set(key, value, epoch = this.epochCounter) {
653
633
  if (epoch !== this.epochCounter) return;
654
- if (this.store.size >= READ_CACHE_MAX_ENTRIES && this.purgeExpired() === 0) {
634
+ if (!this.store.has(key) && this.store.size >= this.maxEntries && this.purgeExpired() === 0) {
655
635
  const oldest = this.store.keys().next();
656
636
  if (!oldest.done) this.store.delete(oldest.value);
657
637
  }
638
+ const now = Date.now();
658
639
  this.store.delete(key);
659
- this.store.set(key, { value: structuredClone(value), expiresAt: Date.now() + this.ttlFor(resource) });
640
+ this.store.set(key, { value: structuredClone(value), storedAt: now, expiresAt: now + this.ttlFor(key) });
641
+ }
642
+ /** `{ hit, age }` without consuming or cloning the entry (age in ms since stored). */
643
+ peek(key) {
644
+ const entry = this.store.get(key);
645
+ if (entry === void 0 || entry.expiresAt <= Date.now()) return { hit: false, age: null };
646
+ return { hit: true, age: Date.now() - entry.storedAt };
647
+ }
648
+ /** The shared in-flight read for `key`, if any. */
649
+ inflight(key) {
650
+ return this.inflightMap.get(key);
651
+ }
652
+ /** Register an in-flight read so concurrent callers share it; dropped on settle. */
653
+ track(key, promise) {
654
+ this.inflightMap.set(key, promise);
655
+ const drop = () => {
656
+ if (this.inflightMap.get(key) === promise) this.inflightMap.delete(key);
657
+ };
658
+ promise.then(drop, drop);
659
+ return promise;
660
+ }
661
+ /** Drop one key. */
662
+ delete(key) {
663
+ this.inflightMap.delete(key);
664
+ return this.store.delete(key);
665
+ }
666
+ /** Drop every stored and in-flight key that starts with `prefix`. */
667
+ invalidate(prefix) {
668
+ for (const key of [...this.store.keys()]) if (key.startsWith(prefix)) this.store.delete(key);
669
+ for (const key of [...this.inflightMap.keys()]) if (key.startsWith(prefix)) this.inflightMap.delete(key);
660
670
  }
661
671
  /** Drop every expired entry (returns the number removed). */
662
672
  purgeExpired() {
@@ -670,24 +680,19 @@ var ReadCache = class {
670
680
  }
671
681
  return removed;
672
682
  }
673
- /** Current entry count (live + not-yet-purged expired). */
683
+ /** Stored entry count (live + not-yet-purged expired). */
674
684
  get size() {
675
685
  return this.store.size;
676
686
  }
677
- /** Drop one key (issue #36: a later positive outcome clears a stale 'absent' marker). */
678
- delete(key) {
679
- return this.store.delete(key);
680
- }
681
- /** The invalidation epoch: bumped by `clear()`; capture it before a wire
682
- * read and pass it to `set` so a read in flight across a write cannot
683
- * re-store its stale answer. */
687
+ /** Bumped by `clear()`; capture it before a wire read and pass it to `set`. */
684
688
  get epoch() {
685
689
  return this.epochCounter;
686
690
  }
687
- /** Drop everything (e.g. a caller that knows the tenant was reset). */
691
+ /** Drop everything and bump the epoch. */
688
692
  clear() {
689
693
  this.epochCounter += 1;
690
694
  this.store.clear();
695
+ this.inflightMap.clear();
691
696
  }
692
697
  };
693
698
 
@@ -790,279 +795,6 @@ var AGENT_PROFILE = {
790
795
  resolution: { maxScanRecords: 200, maxScanPages: 2 }
791
796
  };
792
797
 
793
- // src/cache-ttl-tables.ts
794
- var CACHE_TTL_REFERENCE_MS = 36e5;
795
- var CACHE_TTL_DEFAULT_MS = 3e5;
796
- var DEFAULT_PER_RESOURCE_TTL_MS = {
797
- "appointments": 3e5,
798
- "authenticate": 3e5,
799
- "billing_codes": 36e5,
800
- "billing_item_approval_levels": 3e5,
801
- "billing_items": 3e5,
802
- "change_request_links": 3e5,
803
- "checklist_libraries": 3e5,
804
- "checklist_library_checklist_items": 3e5,
805
- "classification_icons": 3e5,
806
- "companies": 3e5,
807
- "company_alerts": 3e5,
808
- "company_locations": 3e5,
809
- "company_notes": 3e5,
810
- "company_site_configurations": 3e5,
811
- "company_webhooks": 3e5,
812
- "configuration_item_billing_product_associations": 3e5,
813
- "configuration_item_categories": 3e5,
814
- "configuration_item_category_udf_associations": 3e5,
815
- "configuration_item_dns_records": 3e5,
816
- "configuration_item_notes": 3e5,
817
- "configuration_item_related_items": 3e5,
818
- "configuration_item_ssl_subject_alternative_names": 3e5,
819
- "configuration_item_types": 3e5,
820
- "configuration_item_webhooks": 3e5,
821
- "configuration_items": 3e5,
822
- "contact_group_contacts": 3e5,
823
- "contact_groups": 3e5,
824
- "contact_webhooks": 3e5,
825
- "contacts": 3e5,
826
- "contract_billing_rules": 3e5,
827
- "contract_block_hour_factors": 3e5,
828
- "contract_blocks": 3e5,
829
- "contract_charges": 3e5,
830
- "contract_exclusion_billing_codes": 3e5,
831
- "contract_exclusion_roles": 3e5,
832
- "contract_exclusion_set_excluded_roles": 3e5,
833
- "contract_exclusion_set_excluded_work_types": 3e5,
834
- "contract_exclusion_sets": 3e5,
835
- "contract_milestones": 3e5,
836
- "contract_notes": 3e5,
837
- "contract_rates": 3e5,
838
- "contract_retainers": 3e5,
839
- "contract_role_costs": 3e5,
840
- "contract_service_adjustments": 3e5,
841
- "contract_service_bundle_adjustments": 3e5,
842
- "contract_service_bundle_units": 3e5,
843
- "contract_service_bundles": 3e5,
844
- "contract_service_units": 3e5,
845
- "contract_services": 3e5,
846
- "contract_ticket_purchases": 3e5,
847
- "contracts": 3e5,
848
- "countries": 36e5,
849
- "currencies": 3e5,
850
- "departments": 36e5,
851
- "domain_registrars": 3e5,
852
- "entity_information": 3e5,
853
- "expense_item_attachments": 3e5,
854
- "expense_items": 3e5,
855
- "expense_reports": 3e5,
856
- "holiday_sets": 3e5,
857
- "holidays": 3e5,
858
- "inventory_products": 3e5,
859
- "invoice_templates": 3e5,
860
- "invoices": 3e5,
861
- "modules": 3e5,
862
- "notification_history": 3e5,
863
- "opportunities": 3e5,
864
- "opportunity_attachments": 3e5,
865
- "opportunity_categories": 3e5,
866
- "organizational_level1s": 3e5,
867
- "organizational_level2s": 3e5,
868
- "organizational_level_associations": 3e5,
869
- "phases": 36e5,
870
- "product_vendors": 3e5,
871
- "products": 3e5,
872
- "project_charges": 3e5,
873
- "project_notes": 3e5,
874
- "projects": 3e5,
875
- "purchase_approvals": 3e5,
876
- "purchase_order_item_receiving": 3e5,
877
- "purchase_order_items": 3e5,
878
- "purchase_orders": 3e5,
879
- "quote_items": 3e5,
880
- "quote_locations": 3e5,
881
- "quote_templates": 3e5,
882
- "quotes": 3e5,
883
- "resource_role_queues": 3e5,
884
- "resource_roles": 3e5,
885
- "resource_skills": 3e5,
886
- "resource_time_off_additional": 3e5,
887
- "resource_time_off_approvers": 3e5,
888
- "resource_time_off_balances": 3e5,
889
- "resources": 3e5,
890
- "roles": 36e5,
891
- "sales_orders": 3e5,
892
- "service_call_task_resources": 3e5,
893
- "service_call_tasks": 3e5,
894
- "service_call_ticket_resources": 3e5,
895
- "service_call_tickets": 3e5,
896
- "service_calls": 3e5,
897
- "service_level_agreement_results": 3e5,
898
- "services": 36e5,
899
- "skills": 3e5,
900
- "subscription_periods": 3e5,
901
- "subscriptions": 3e5,
902
- "survey_results": 3e5,
903
- "surveys": 3e5,
904
- "tag_aliases": 3e5,
905
- "tag_groups": 3e5,
906
- "tags": 3e5,
907
- "task_secondary_resources": 3e5,
908
- "tasks": 3e5,
909
- "tax_regions": 3e5,
910
- "threshold_information": 3e5,
911
- "ticket_additional_configuration_items": 3e5,
912
- "ticket_additional_contacts": 3e5,
913
- "ticket_attachments": 3e5,
914
- "ticket_categories": 3e5,
915
- "ticket_category_field_defaults": 3e5,
916
- "ticket_change_request_approvals": 3e5,
917
- "ticket_charges": 3e5,
918
- "ticket_checklist_items": 3e5,
919
- "ticket_checklist_libraries": 3e5,
920
- "ticket_history": 3e5,
921
- "ticket_note_attachments": 3e5,
922
- "ticket_note_webhooks": 3e5,
923
- "ticket_notes": 3e5,
924
- "ticket_secondary_resources": 3e5,
925
- "ticket_webhooks": 3e5,
926
- "tickets": 3e5,
927
- "time_entries": 3e5,
928
- "time_entry_attachments": 3e5,
929
- "time_off_requests": 3e5,
930
- "version": 3e5,
931
- "version_information": 3e5,
932
- "zone_information": 3e5
933
- };
934
- var RESOURCE_KEY_BY_PATH = {
935
- "/V1.0/Appointments": "appointments",
936
- "/V1.0/BillingCodes": "billing_codes",
937
- "/V1.0/BillingItemApprovalLevels": "billing_item_approval_levels",
938
- "/V1.0/BillingItems": "billing_items",
939
- "/V1.0/ChangeRequestLinks": "change_request_links",
940
- "/V1.0/ChecklistLibraries": "checklist_libraries",
941
- "/V1.0/ChecklistLibraryChecklistItems": "checklist_library_checklist_items",
942
- "/V1.0/ClassificationIcons": "classification_icons",
943
- "/V1.0/Companies": "companies",
944
- "/V1.0/CompanyAlerts": "company_alerts",
945
- "/V1.0/CompanyLocations": "company_locations",
946
- "/V1.0/CompanyNotes": "company_notes",
947
- "/V1.0/CompanySiteConfigurations": "company_site_configurations",
948
- "/V1.0/CompanyWebhooks": "company_webhooks",
949
- "/V1.0/ConfigurationItemBillingProductAssociations": "configuration_item_billing_product_associations",
950
- "/V1.0/ConfigurationItemCategories": "configuration_item_categories",
951
- "/V1.0/ConfigurationItemCategoryUdfAssociations": "configuration_item_category_udf_associations",
952
- "/V1.0/ConfigurationItemDnsRecords": "configuration_item_dns_records",
953
- "/V1.0/ConfigurationItemNotes": "configuration_item_notes",
954
- "/V1.0/ConfigurationItemRelatedItems": "configuration_item_related_items",
955
- "/V1.0/ConfigurationItemSslSubjectAlternativeNames": "configuration_item_ssl_subject_alternative_names",
956
- "/V1.0/ConfigurationItemTypes": "configuration_item_types",
957
- "/V1.0/ConfigurationItemWebhooks": "configuration_item_webhooks",
958
- "/V1.0/ConfigurationItems": "configuration_items",
959
- "/V1.0/ContactGroupContacts": "contact_group_contacts",
960
- "/V1.0/ContactGroups": "contact_groups",
961
- "/V1.0/ContactWebhooks": "contact_webhooks",
962
- "/V1.0/Contacts": "contacts",
963
- "/V1.0/ContractBillingRules": "contract_billing_rules",
964
- "/V1.0/ContractBlockHourFactors": "contract_block_hour_factors",
965
- "/V1.0/ContractBlocks": "contract_blocks",
966
- "/V1.0/ContractCharges": "contract_charges",
967
- "/V1.0/ContractExclusionBillingCodes": "contract_exclusion_billing_codes",
968
- "/V1.0/ContractExclusionRoles": "contract_exclusion_roles",
969
- "/V1.0/ContractExclusionSetExcludedRoles": "contract_exclusion_set_excluded_roles",
970
- "/V1.0/ContractExclusionSetExcludedWorkTypes": "contract_exclusion_set_excluded_work_types",
971
- "/V1.0/ContractExclusionSets": "contract_exclusion_sets",
972
- "/V1.0/ContractMilestones": "contract_milestones",
973
- "/V1.0/ContractNotes": "contract_notes",
974
- "/V1.0/ContractRates": "contract_rates",
975
- "/V1.0/ContractRetainers": "contract_retainers",
976
- "/V1.0/ContractRoleCosts": "contract_role_costs",
977
- "/V1.0/ContractServiceAdjustments": "contract_service_adjustments",
978
- "/V1.0/ContractServiceBundleAdjustments": "contract_service_bundle_adjustments",
979
- "/V1.0/ContractServiceBundleUnits": "contract_service_bundle_units",
980
- "/V1.0/ContractServiceBundles": "contract_service_bundles",
981
- "/V1.0/ContractServiceUnits": "contract_service_units",
982
- "/V1.0/ContractServices": "contract_services",
983
- "/V1.0/ContractTicketPurchases": "contract_ticket_purchases",
984
- "/V1.0/Contracts": "contracts",
985
- "/V1.0/Countries": "countries",
986
- "/V1.0/Currencies": "currencies",
987
- "/V1.0/Departments": "departments",
988
- "/V1.0/DomainRegistrars": "domain_registrars",
989
- "/V1.0/ExpenseItemAttachments": "expense_item_attachments",
990
- "/V1.0/ExpenseItems": "expense_items",
991
- "/V1.0/ExpenseReports": "expense_reports",
992
- "/V1.0/HolidaySets": "holiday_sets",
993
- "/V1.0/Holidays": "holidays",
994
- "/V1.0/InventoryProducts": "inventory_products",
995
- "/V1.0/InvoiceTemplates": "invoice_templates",
996
- "/V1.0/Invoices": "invoices",
997
- "/V1.0/NotificationHistory": "notification_history",
998
- "/V1.0/Opportunities": "opportunities",
999
- "/V1.0/OpportunityAttachments": "opportunity_attachments",
1000
- "/V1.0/OpportunityCategories": "opportunity_categories",
1001
- "/V1.0/OrganizationalLevel1s": "organizational_level1s",
1002
- "/V1.0/OrganizationalLevel2s": "organizational_level2s",
1003
- "/V1.0/OrganizationalLevelAssociations": "organizational_level_associations",
1004
- "/V1.0/Phases": "phases",
1005
- "/V1.0/ProductVendors": "product_vendors",
1006
- "/V1.0/Products": "products",
1007
- "/V1.0/ProjectCharges": "project_charges",
1008
- "/V1.0/ProjectNotes": "project_notes",
1009
- "/V1.0/Projects": "projects",
1010
- "/V1.0/PurchaseApprovals": "purchase_approvals",
1011
- "/V1.0/PurchaseOrderItemReceiving": "purchase_order_item_receiving",
1012
- "/V1.0/PurchaseOrderItems": "purchase_order_items",
1013
- "/V1.0/PurchaseOrders": "purchase_orders",
1014
- "/V1.0/QuoteItems": "quote_items",
1015
- "/V1.0/QuoteLocations": "quote_locations",
1016
- "/V1.0/QuoteTemplates": "quote_templates",
1017
- "/V1.0/Quotes": "quotes",
1018
- "/V1.0/ResourceRoleQueues": "resource_role_queues",
1019
- "/V1.0/ResourceRoles": "resource_roles",
1020
- "/V1.0/ResourceSkills": "resource_skills",
1021
- "/V1.0/ResourceTimeOffAdditional": "resource_time_off_additional",
1022
- "/V1.0/ResourceTimeOffApprovers": "resource_time_off_approvers",
1023
- "/V1.0/ResourceTimeOffBalances": "resource_time_off_balances",
1024
- "/V1.0/Resources": "resources",
1025
- "/V1.0/Roles": "roles",
1026
- "/V1.0/SalesOrders": "sales_orders",
1027
- "/V1.0/ServiceCallTaskResources": "service_call_task_resources",
1028
- "/V1.0/ServiceCallTasks": "service_call_tasks",
1029
- "/V1.0/ServiceCallTicketResources": "service_call_ticket_resources",
1030
- "/V1.0/ServiceCallTickets": "service_call_tickets",
1031
- "/V1.0/ServiceCalls": "service_calls",
1032
- "/V1.0/ServiceLevelAgreementResults": "service_level_agreement_results",
1033
- "/V1.0/Services": "services",
1034
- "/V1.0/Skills": "skills",
1035
- "/V1.0/SubscriptionPeriods": "subscription_periods",
1036
- "/V1.0/Subscriptions": "subscriptions",
1037
- "/V1.0/SurveyResults": "survey_results",
1038
- "/V1.0/Surveys": "surveys",
1039
- "/V1.0/TagAliases": "tag_aliases",
1040
- "/V1.0/TagGroups": "tag_groups",
1041
- "/V1.0/Tags": "tags",
1042
- "/V1.0/TaskSecondaryResources": "task_secondary_resources",
1043
- "/V1.0/Tasks": "tasks",
1044
- "/V1.0/TaxRegions": "tax_regions",
1045
- "/V1.0/TicketAdditionalConfigurationItems": "ticket_additional_configuration_items",
1046
- "/V1.0/TicketAdditionalContacts": "ticket_additional_contacts",
1047
- "/V1.0/TicketAttachments": "ticket_attachments",
1048
- "/V1.0/TicketCategories": "ticket_categories",
1049
- "/V1.0/TicketCategoryFieldDefaults": "ticket_category_field_defaults",
1050
- "/V1.0/TicketChangeRequestApprovals": "ticket_change_request_approvals",
1051
- "/V1.0/TicketCharges": "ticket_charges",
1052
- "/V1.0/TicketChecklistItems": "ticket_checklist_items",
1053
- "/V1.0/TicketChecklistLibraries": "ticket_checklist_libraries",
1054
- "/V1.0/TicketHistory": "ticket_history",
1055
- "/V1.0/TicketNoteAttachments": "ticket_note_attachments",
1056
- "/V1.0/TicketNoteWebhooks": "ticket_note_webhooks",
1057
- "/V1.0/TicketNotes": "ticket_notes",
1058
- "/V1.0/TicketSecondaryResources": "ticket_secondary_resources",
1059
- "/V1.0/TicketWebhooks": "ticket_webhooks",
1060
- "/V1.0/Tickets": "tickets",
1061
- "/V1.0/TimeEntries": "time_entries",
1062
- "/V1.0/TimeEntryAttachments": "time_entry_attachments",
1063
- "/V1.0/TimeOffRequests": "time_off_requests"
1064
- };
1065
-
1066
798
  // src/config/defaults.ts
1067
799
  var DEFAULT_PAGE_SIZE = 10;
1068
800
  var MAX_PAGE_SIZE = 500;
@@ -1075,9 +807,8 @@ var DEFAULT_MAX_CONCURRENT = 10;
1075
807
  var DEFAULT_MAX_RESPONSE_BYTES = 64 * 1024 * 1024;
1076
808
  var DEFAULT_MAX_SCAN_RECORDS = 500;
1077
809
  var DEFAULT_MAX_SCAN_PAGES = 4;
1078
- var DEFAULT_READ_CACHE_TTL_MS = CACHE_TTL_DEFAULT_MS;
1079
- var DEFAULT_FIELD_CACHE_TTL_MS = CACHE_TTL_DEFAULT_MS;
1080
- var DEFAULT_RESOURCE_NAME_CACHE_TTL_MS = CACHE_TTL_REFERENCE_MS;
810
+ var DEFAULT_READ_CACHE_TTL_MS = 3e5;
811
+ var DEFAULT_FIELD_CACHE_TTL_MS = 3e5;
1081
812
 
1082
813
  // src/credential-shape.ts
1083
814
  var QUOTE_CHARS = /* @__PURE__ */ new Set(["'", '"']);
@@ -1104,390 +835,105 @@ function credentialValueSummary(value) {
1104
835
  return value.length >= MIN_PREFIX_SUMMARY_LENGTH ? `len ${value.length}, starts "${value.slice(0, 2)}"` : "short value (length withheld)";
1105
836
  }
1106
837
 
1107
- // src/fieldCache.ts
1108
- var FIELD_CACHE_MAX_ENTITIES = 256;
1109
- var FIELD_CACHE_KINDS = ["info", "fields", "udf"];
1110
- var FieldCache = class _FieldCache {
1111
- /** The configured TTL in ms. */
1112
- ttlMs;
1113
- /** The entity bound (the cap applies to STORED entries; inflight never counts). */
1114
- maxEntities;
1115
- store = /* @__PURE__ */ new Map();
1116
- inflightMap = /* @__PURE__ */ new Map();
1117
- constructor(ttlMs, maxEntities = FIELD_CACHE_MAX_ENTITIES) {
1118
- if (!Number.isInteger(ttlMs) || ttlMs <= 0) {
1119
- throw new AutotaskConfigError(`fieldCache.ttlMs must be a positive integer (got ${ttlMs})`);
1120
- }
1121
- if (!Number.isInteger(maxEntities) || maxEntities <= 0) {
1122
- throw new AutotaskConfigError(`fieldCache.maxEntities must be a positive integer (got ${maxEntities})`);
1123
- }
1124
- this.ttlMs = ttlMs;
1125
- this.maxEntities = maxEntities;
1126
- }
1127
- /** The composite key: one entity's catalogs are one key apart. */
1128
- static key(resourceKey, kind) {
1129
- return `${resourceKey}:${kind}`;
1130
- }
1131
- /**
1132
- * Read-through lookup: the live entry's value (a copy), or `undefined`
1133
- * (absent OR expired — an expired entry is purged lazily on this read).
1134
- */
1135
- get(resourceKey, kind) {
1136
- const entry = this.store.get(_FieldCache.key(resourceKey, kind));
1137
- if (entry === void 0) return void 0;
1138
- if (entry.expiresAt <= Date.now()) {
1139
- this.store.delete(_FieldCache.key(resourceKey, kind));
1140
- return void 0;
1141
- }
1142
- return structuredClone(entry.value);
1143
- }
1144
- /**
1145
- * Store a SUCCESSFUL, NON-EMPTY metadata value under (entity, kind),
1146
- * live for `ttlMs`. An EMPTY value (`[]` / `{}` / null) is refused
1147
- * silently (never cached — an empty is not an answer): the next call
1148
- * refetches.
1149
- */
1150
- set(resourceKey, kind, value) {
1151
- if (_FieldCache.isEmpty(value)) return;
1152
- const key = _FieldCache.key(resourceKey, kind);
1153
- if (this.store.size >= this.maxEntities && this.purgeExpired() === 0) {
1154
- const oldest = this.store.keys().next();
1155
- if (!oldest.done) this.store.delete(oldest.value);
1156
- }
1157
- this.store.delete(key);
1158
- this.store.set(key, { value: structuredClone(value), expiresAt: Date.now() + this.ttlMs });
1159
- }
1160
- /** True for the values that must never be cached (an empty is not an answer). */
1161
- static isEmpty(value) {
1162
- if (value === null || value === void 0) return true;
1163
- if (Array.isArray(value)) return value.length === 0;
1164
- if (typeof value === "object") return Object.keys(value).length === 0;
1165
- return false;
1166
- }
1167
- /**
1168
- * In-flight de-duplication: the shared in-flight promise for
1169
- * (entity, kind), or `undefined` (nothing in flight — the caller
1170
- * issues the request and registers it with `track`).
1171
- */
1172
- inflight(resourceKey, kind) {
1173
- return this.inflightMap.get(_FieldCache.key(resourceKey, kind));
1174
- }
1175
- /**
1176
- * Register an in-flight metadata read: concurrent callers for the same
1177
- * (entity, kind) await the SAME promise (one wire request). The entry
1178
- * is dropped on settle — success OR failure (a failure is never
1179
- * cached; the next caller refetches).
1180
- */
1181
- track(resourceKey, kind, promise) {
1182
- const key = _FieldCache.key(resourceKey, kind);
1183
- this.inflightMap.set(key, promise);
1184
- promise.then(
1185
- () => {
1186
- this.inflightMap.delete(key);
1187
- },
1188
- () => {
1189
- this.inflightMap.delete(key);
1190
- }
1191
- );
1192
- return promise;
1193
- }
1194
- /**
1195
- * The drift signal: drop the entity's STORED entries AND its in-flight
1196
- * promise (a refetch must not join a request whose premise just moved).
1197
- * A no-op when the entity holds nothing.
1198
- */
1199
- invalidate(resourceKey) {
1200
- for (const kind of FIELD_CACHE_KINDS) {
1201
- const key = _FieldCache.key(resourceKey, kind);
1202
- this.store.delete(key);
1203
- this.inflightMap.delete(key);
1204
- }
1205
- }
1206
- /**
1207
- * A non-mutating probe for the served op's per-row `cache` report:
1208
- * `hit` = a live (unexpired) entry exists; `age` = ms since that entry
1209
- * was stored (null when `hit` is false). Never purges, never clones.
1210
- */
1211
- peek(resourceKey, kind) {
1212
- const entry = this.store.get(_FieldCache.key(resourceKey, kind));
1213
- if (entry === void 0 || entry.expiresAt <= Date.now()) {
1214
- return { hit: false, age: null };
1215
- }
1216
- return { hit: true, age: Date.now() - (entry.expiresAt - this.ttlMs) };
1217
- }
1218
- /** Drop every expired entry (returns the number removed). */
1219
- purgeExpired() {
1220
- const now = Date.now();
1221
- let removed = 0;
1222
- for (const [key, entry] of this.store) {
1223
- if (entry.expiresAt <= now) {
1224
- this.store.delete(key);
1225
- removed += 1;
1226
- }
1227
- }
1228
- return removed;
1229
- }
1230
- /** Current entry count (live + not-yet-purged expired). */
1231
- get size() {
1232
- return this.store.size;
1233
- }
1234
- /** Drop everything (e.g. a caller that knows the tenant was reset). */
1235
- clear() {
1236
- this.store.clear();
1237
- this.inflightMap.clear();
1238
- }
1239
- };
1240
-
1241
- // src/circuit-breaker.ts
1242
- var DEFAULT_CIRCUIT_BREAKER_WINDOW_MS = 1e4;
1243
- var DEFAULT_CIRCUIT_BREAKER_FAILURE_THRESHOLD = 5;
1244
- var DEFAULT_CIRCUIT_BREAKER_OPEN_TIMEOUT_MS = 3e4;
1245
- var DEFAULT_CIRCUIT_BREAKER_SUCCESSES_TO_CLOSE = 2;
1246
- var DEFAULT_CIRCUIT_BREAKER_MAX_ENTRIES = 1024;
1247
- var InMemoryCircuitBreakerStore = class {
1248
- maxEntries;
1249
- states = /* @__PURE__ */ new Map();
1250
- constructor(maxEntries = DEFAULT_CIRCUIT_BREAKER_MAX_ENTRIES) {
1251
- if (!Number.isInteger(maxEntries) || maxEntries <= 0) {
1252
- throw new TypeError(`InMemoryCircuitBreakerStore maxEntries must be a positive integer (got ${String(maxEntries)})`);
1253
- }
1254
- this.maxEntries = maxEntries;
1255
- }
1256
- get(hostKey) {
1257
- return this.states.get(hostKey);
1258
- }
1259
- set(hostKey, state) {
1260
- if (this.states.has(hostKey)) {
1261
- this.states.set(hostKey, state);
1262
- return;
1263
- }
1264
- if (this.states.size >= this.maxEntries) {
1265
- let victim;
1266
- let victimActivity = Number.POSITIVE_INFINITY;
1267
- for (const [key, s] of this.states) {
1268
- const activity = s.openedAt !== null ? s.openedAt : s.failures.length > 0 ? s.failures[s.failures.length - 1] : 0;
1269
- if (activity < victimActivity) {
1270
- victimActivity = activity;
1271
- victim = key;
1272
- }
1273
- }
1274
- if (victim !== void 0) this.states.delete(victim);
1275
- }
1276
- this.states.set(hostKey, state);
1277
- }
1278
- delete(hostKey) {
1279
- this.states.delete(hostKey);
1280
- }
1281
- /** Drop every entry (test helper surface; also used by resetDefaultCircuitBreakerStore). */
1282
- clear() {
1283
- this.states.clear();
1284
- }
1285
- };
1286
- var defaultStore;
1287
- function defaultCircuitBreakerStore() {
1288
- if (defaultStore === void 0) defaultStore = new InMemoryCircuitBreakerStore();
1289
- return defaultStore;
1290
- }
1291
- function resetDefaultCircuitBreakerStore() {
1292
- defaultStore?.clear();
1293
- }
1294
- function buildBreakerKey(baseUrl) {
1295
- return new URL(baseUrl).host.toLowerCase();
1296
- }
1297
- function isBreakerFailure(err) {
1298
- if (err.notSent === true) return false;
1299
- if (err.code === "NETWORK_ERROR" || err.code === "TIMEOUT") return true;
1300
- const status = err.httpStatus;
1301
- if (status === void 0) return false;
1302
- if (status === 429) return true;
1303
- if (status >= 500 && status < 600) {
1304
- return err.details?.deterministic !== true;
1305
- }
1306
- return err.code === "UNEXPECTED_CONTENT_TYPE";
1307
- }
1308
-
1309
- // src/cooldown.ts
838
+ // src/http/gates.ts
1310
839
  var DEFAULT_COOLDOWN_MAX_MS = 15 * 60 * 1e3;
1311
840
  var DEFAULT_COOLDOWN_DEFAULT_MS = 6e4;
1312
- var DEFAULT_COOLDOWN_MAX_ENTRIES = 1024;
1313
841
  var THREAD_THRESHOLD_MAX_MS = 1e4;
1314
842
  var THREAD_THRESHOLD_DEFAULT_MS = 5e3;
1315
- var InMemoryCooldownStore = class {
1316
- maxEntries;
1317
- deadlines = /* @__PURE__ */ new Map();
1318
- constructor(maxEntries = DEFAULT_COOLDOWN_MAX_ENTRIES) {
1319
- if (!Number.isInteger(maxEntries) || maxEntries <= 0) {
1320
- throw new TypeError(`InMemoryCooldownStore maxEntries must be a positive integer (got ${String(maxEntries)})`);
1321
- }
1322
- this.maxEntries = maxEntries;
1323
- }
1324
- get(tenantKey) {
1325
- return this.deadlines.get(tenantKey);
843
+ var cooldowns = /* @__PURE__ */ new Map();
844
+ var maintenance = /* @__PURE__ */ new Map();
845
+ function hostKey(baseUrl) {
846
+ return new URL(baseUrl).host.toLowerCase();
847
+ }
848
+ function tenantKey(userName, baseUrl) {
849
+ return `${userName.toLowerCase()}@${hostKey(baseUrl)}`;
850
+ }
851
+ function cooldownRefusal(key, ctx) {
852
+ const deadline = cooldowns.get(key);
853
+ if (deadline === void 0) return void 0;
854
+ const remainingMs = deadline - Date.now();
855
+ if (remainingMs <= 0) {
856
+ cooldowns.delete(key);
857
+ return void 0;
1326
858
  }
1327
- set(tenantKey, deadline) {
1328
- if (this.deadlines.has(tenantKey)) {
1329
- this.deadlines.set(tenantKey, deadline);
1330
- return;
1331
- }
1332
- if (this.deadlines.size >= this.maxEntries) {
1333
- let victim;
1334
- let victimDeadline = Number.POSITIVE_INFINITY;
1335
- for (const [key, d] of this.deadlines) {
1336
- if (d < victimDeadline) {
1337
- victimDeadline = d;
1338
- victim = key;
1339
- }
1340
- }
1341
- if (victim !== void 0) this.deadlines.delete(victim);
859
+ const seconds = Math.ceil(remainingMs / 1e3);
860
+ const err = new RateLimitError(
861
+ `Tenant is in a rate-limit cooldown; the call was NOT sent. ${seconds}s remain \u2014 do not retry before then, and narrow the query (filter/includeFields) before retrying.`,
862
+ {
863
+ ...ctx,
864
+ code: "RATE_LIMITED_COOLDOWN",
865
+ retryable: false,
866
+ suggestedAction: `Wait ${seconds}s (per-tenant 429 cooldown) and retry with a narrower query; the call was not sent and consumed no vendor budget.`
1342
867
  }
1343
- this.deadlines.set(tenantKey, deadline);
1344
- }
1345
- delete(tenantKey) {
1346
- this.deadlines.delete(tenantKey);
1347
- }
1348
- /** Drop every entry (test helper surface; also used by resetDefaultCooldownStore). */
1349
- clear() {
1350
- this.deadlines.clear();
1351
- }
1352
- };
1353
- var defaultStore2;
1354
- function defaultCooldownStore() {
1355
- if (defaultStore2 === void 0) defaultStore2 = new InMemoryCooldownStore();
1356
- return defaultStore2;
868
+ );
869
+ err.retryAfter = seconds;
870
+ err.notSent = true;
871
+ return err;
1357
872
  }
1358
- function resetDefaultCooldownStore() {
1359
- defaultStore2?.clear();
873
+ function armCooldown(key, deadline) {
874
+ const now = Date.now();
875
+ for (const [k, d] of cooldowns) if (d <= now) cooldowns.delete(k);
876
+ cooldowns.set(key, deadline);
1360
877
  }
1361
- function buildTenantKey(userName, baseUrl) {
1362
- return `${userName.toLowerCase()}@${new URL(baseUrl).host.toLowerCase()}`;
878
+ function clearCooldown(key) {
879
+ cooldowns.delete(key);
1363
880
  }
1364
881
  function cooldownDurationMs(retryAfterSecs, opts) {
1365
882
  if (opts.threadThreshold) {
1366
- const secs = retryAfterSecs !== void 0 ? Math.min(retryAfterSecs, Math.round(THREAD_THRESHOLD_MAX_MS / 1e3)) : Math.round(THREAD_THRESHOLD_DEFAULT_MS / 1e3);
1367
- return Math.max(0, secs) * 1e3;
883
+ const ms = retryAfterSecs !== void 0 ? Math.min(retryAfterSecs * 1e3, THREAD_THRESHOLD_MAX_MS) : THREAD_THRESHOLD_DEFAULT_MS;
884
+ return Math.max(0, ms);
1368
885
  }
1369
- const rawMs = retryAfterSecs !== void 0 ? retryAfterSecs * 1e3 : opts.defaultMs;
1370
- return Math.min(rawMs, opts.maxMs);
886
+ return Math.min(retryAfterSecs !== void 0 ? retryAfterSecs * 1e3 : opts.defaultMs, opts.maxMs);
1371
887
  }
1372
-
1373
- // src/resourceNameCache.ts
1374
- var RESOURCE_NAME_CACHE_MAX_ENTRIES = 1024;
1375
- var RESOURCE_NAME_CACHE_BLIND_TTL_MS = 6e4;
1376
- var ResourceNameCache = class _ResourceNameCache {
1377
- /** The configured TTL in ms. */
1378
- ttlMs;
1379
- /** The entry bound (the cap applies to STORED entries; inflight never counts). */
1380
- maxEntries;
1381
- store = /* @__PURE__ */ new Map();
1382
- inflightMap = /* @__PURE__ */ new Map();
1383
- epochCounter = 0;
1384
- constructor(ttlMs, maxEntries = RESOURCE_NAME_CACHE_MAX_ENTRIES) {
1385
- if (!Number.isInteger(ttlMs) || ttlMs <= 0) {
1386
- throw new AutotaskConfigError(`resourceNameCache.ttlMs must be a positive integer (got ${ttlMs})`);
1387
- }
1388
- if (!Number.isInteger(maxEntries) || maxEntries <= 0) {
1389
- throw new AutotaskConfigError(`resourceNameCache.maxEntries must be a positive integer (got ${maxEntries})`);
1390
- }
1391
- this.ttlMs = ttlMs;
1392
- this.maxEntries = maxEntries;
1393
- }
1394
- /** The namespaced key: `resources:<canonical id>` (the namespace
1395
- * leaves a documented path to future FK tables — v1 serves
1396
- * `resources` only). */
1397
- static key(id) {
1398
- return `resources:${id}`;
1399
- }
1400
- /**
1401
- * Read-through lookup: the live entry (a copy), or `undefined`
1402
- * (absent OR expired — an expired entry is purged lazily on this
1403
- * read).
1404
- */
1405
- get(id) {
1406
- const entry = this.store.get(_ResourceNameCache.key(id));
1407
- if (entry === void 0) return void 0;
1408
- if (entry.expiresAt <= Date.now()) {
1409
- this.store.delete(_ResourceNameCache.key(id));
1410
- return void 0;
1411
- }
1412
- return structuredClone(entry.value);
1413
- }
1414
- /**
1415
- * Store a name answer under the id, live for `ttlMs`. ALWAYS stores
1416
- * (the no-name-part answer `{ name: null, blind: false }` is a stable
1417
- * fact and is cached — the documented difference from the fieldCache
1418
- * empty rule); past the cap, purge expired first, then evict the
1419
- * oldest-inserted (Map insertion order; refreshes re-insert so the
1420
- * memory guard drops the OLDEST-inserted entries first).
1421
- */
1422
- set(id, value, epoch = this.epochCounter) {
1423
- if (epoch !== this.epochCounter) return;
1424
- const key = _ResourceNameCache.key(id);
1425
- if (!this.store.has(key) && this.store.size >= this.maxEntries && this.purgeExpired() === 0) {
1426
- const oldest = this.store.keys().next();
1427
- if (!oldest.done) this.store.delete(oldest.value);
1428
- }
1429
- this.store.delete(key);
1430
- this.store.set(key, { value: structuredClone(value), expiresAt: Date.now() + (value.blind ? Math.min(this.ttlMs, RESOURCE_NAME_CACHE_BLIND_TTL_MS) : this.ttlMs) });
1431
- }
1432
- /**
1433
- * In-flight de-duplication: the shared in-flight promise for the id,
1434
- * or `undefined` (nothing in flight — the caller issues the request
1435
- * and registers it with `track`).
1436
- */
1437
- inflight(id) {
1438
- return this.inflightMap.get(_ResourceNameCache.key(id));
1439
- }
1440
- /**
1441
- * Register an in-flight name read: concurrent callers for the same id
1442
- * await the SAME promise (one wire request). The entry is dropped on
1443
- * settle — success OR failure (a failure is never cached; the next
1444
- * caller refetches).
1445
- */
1446
- track(id, promise) {
1447
- const key = _ResourceNameCache.key(id);
1448
- this.inflightMap.set(key, promise);
1449
- promise.then(
1450
- () => {
1451
- this.inflightMap.delete(key);
1452
- },
1453
- () => {
1454
- this.inflightMap.delete(key);
1455
- }
1456
- );
1457
- return promise;
1458
- }
1459
- /** Drop every expired entry (returns the number removed). */
1460
- purgeExpired() {
1461
- const now = Date.now();
1462
- let removed = 0;
1463
- for (const [key, entry] of this.store) {
1464
- if (entry.expiresAt <= now) {
1465
- this.store.delete(key);
1466
- removed += 1;
1467
- }
888
+ function admitMaintenance(host, ctx) {
889
+ const gate = maintenance.get(host);
890
+ if (gate === void 0) return "send";
891
+ const now = Date.now();
892
+ if (!gate.probing && now >= gate.nextProbeAt) {
893
+ gate.probing = true;
894
+ return gate;
895
+ }
896
+ const retryAfterMs = gate.probing ? Math.max(gate.nextProbeAt - now, gate.pollMs) : Math.max(0, gate.nextProbeAt - now);
897
+ const seconds = Math.max(1, Math.ceil(retryAfterMs / 1e3));
898
+ const since = new Date(gate.since).toISOString();
899
+ const err = new MaintenanceError(
900
+ `Zone ${host} is in a maintenance window (since ${since}); the call was NOT sent. Retry in about ${seconds}s.`,
901
+ {
902
+ ...ctx,
903
+ details: { since, retryAfterMs },
904
+ suggestedAction: `The Autotask zone is in its maintenance window (since ${since}). The call was not sent; retry later (the next probe is in about ${seconds}s, windows usually last 30-90 min).`
1468
905
  }
1469
- return removed;
1470
- }
1471
- /** The invalidation epoch: bumped by `clear()`; capture it before a wire
1472
- * read and pass it to `set` so a stale answer is dropped. */
1473
- get epoch() {
1474
- return this.epochCounter;
1475
- }
1476
- /** Current entry count (live + not-yet-purged expired). */
1477
- get size() {
1478
- return this.store.size;
1479
- }
1480
- /**
1481
- * Drop everything — the SCOPED invalidation target: a real write to
1482
- * the `resources` resource through the same client (a rename via this
1483
- * client is always fresh).
1484
- */
1485
- clear() {
1486
- this.epochCounter += 1;
1487
- this.store.clear();
1488
- this.inflightMap.clear();
1489
- }
1490
- };
906
+ );
907
+ err.retryAfter = seconds;
908
+ err.notSent = true;
909
+ return err;
910
+ }
911
+ function openMaintenance(host, pollMs, logger, correlationId) {
912
+ if (maintenance.has(host)) return;
913
+ const now = Date.now();
914
+ maintenance.set(host, { since: now, pollMs, nextProbeAt: now + pollMs, probing: false });
915
+ logger.warn?.(`[autotask] maintenance gate OPEN for ${host}: other calls on this zone fail fast (MAINTENANCE) until a probe sees a normal response`, correlationId);
916
+ }
917
+ function claimMaintenanceProbe(host) {
918
+ const gate = maintenance.get(host);
919
+ if (gate === void 0 || gate.probing) return void 0;
920
+ gate.probing = true;
921
+ return gate;
922
+ }
923
+ function releaseMaintenanceProbe(host, gate) {
924
+ if (maintenance.get(host) !== gate) return;
925
+ gate.probing = false;
926
+ gate.nextProbeAt = Date.now() + gate.pollMs;
927
+ }
928
+ function closeMaintenance(host, logger, correlationId) {
929
+ const gate = maintenance.get(host);
930
+ if (gate === void 0) return;
931
+ maintenance.delete(host);
932
+ logger.warn?.(`[autotask] maintenance gate CLOSED for ${host} after ${Math.round((Date.now() - gate.since) / 1e3)}s`, correlationId);
933
+ }
934
+ function maintenanceSince(host) {
935
+ return maintenance.get(host)?.since;
936
+ }
1491
937
 
1492
938
  // src/host-policy.ts
1493
939
  function canonicalHost(origin) {
@@ -1779,61 +1225,10 @@ function resolveCooldown(config) {
1779
1225
  if (!Number.isInteger(cooldownDefaultMs) || cooldownDefaultMs <= 0) {
1780
1226
  throw new AutotaskConfigError("cooldown.defaultMs must be a positive integer (ms)");
1781
1227
  }
1782
- const cooldownStore = config.cooldown?.store;
1783
- if (cooldownStore !== void 0 && (typeof cooldownStore.get !== "function" || typeof cooldownStore.set !== "function" || typeof cooldownStore.delete !== "function")) {
1784
- throw new AutotaskConfigError("cooldown.store must implement get/set/delete (a CooldownStore)");
1785
- }
1786
1228
  return {
1787
1229
  enabled: cooldownEnabled,
1788
1230
  maxMs: cooldownMaxMs,
1789
- defaultMs: cooldownDefaultMs,
1790
- store: cooldownStore
1791
- };
1792
- }
1793
- function resolveCircuitBreaker(config) {
1794
- const breakerEnabled = config.circuitBreaker?.enabled ?? false;
1795
- const breakerWindowMs = config.circuitBreaker?.failureWindowMs ?? DEFAULT_CIRCUIT_BREAKER_WINDOW_MS;
1796
- if (!Number.isInteger(breakerWindowMs) || breakerWindowMs <= 0) {
1797
- throw new AutotaskConfigError("circuitBreaker.failureWindowMs must be a positive integer (ms)");
1798
- }
1799
- const breakerThreshold = config.circuitBreaker?.failureThreshold ?? DEFAULT_CIRCUIT_BREAKER_FAILURE_THRESHOLD;
1800
- if (!Number.isInteger(breakerThreshold) || breakerThreshold <= 0) {
1801
- throw new AutotaskConfigError("circuitBreaker.failureThreshold must be a positive integer");
1802
- }
1803
- const breakerOpenTimeoutMs = config.circuitBreaker?.openTimeoutMs ?? DEFAULT_CIRCUIT_BREAKER_OPEN_TIMEOUT_MS;
1804
- if (!Number.isInteger(breakerOpenTimeoutMs) || breakerOpenTimeoutMs <= 0) {
1805
- throw new AutotaskConfigError("circuitBreaker.openTimeoutMs must be a positive integer (ms)");
1806
- }
1807
- const breakerSuccessesToClose = config.circuitBreaker?.successesToClose ?? DEFAULT_CIRCUIT_BREAKER_SUCCESSES_TO_CLOSE;
1808
- if (!Number.isInteger(breakerSuccessesToClose) || breakerSuccessesToClose <= 0) {
1809
- throw new AutotaskConfigError("circuitBreaker.successesToClose must be a positive integer");
1810
- }
1811
- const breakerHalfOpenProbes = config.circuitBreaker?.halfOpenProbes ?? breakerSuccessesToClose;
1812
- if (!Number.isInteger(breakerHalfOpenProbes) || breakerHalfOpenProbes <= 0) {
1813
- throw new AutotaskConfigError("circuitBreaker.halfOpenProbes must be a positive integer");
1814
- }
1815
- if (breakerHalfOpenProbes < breakerSuccessesToClose) {
1816
- throw new AutotaskConfigError(
1817
- `circuitBreaker.halfOpenProbes (${breakerHalfOpenProbes}) must be >= successesToClose (${breakerSuccessesToClose}) \u2014 the breaker could never close`
1818
- );
1819
- }
1820
- const breakerStore = config.circuitBreaker?.store;
1821
- if (breakerStore !== void 0 && (typeof breakerStore.get !== "function" || typeof breakerStore.set !== "function" || typeof breakerStore.delete !== "function")) {
1822
- throw new AutotaskConfigError("circuitBreaker.store must implement get/set/delete (a CircuitBreakerStore)");
1823
- }
1824
- const breakerIsFailure = config.circuitBreaker?.isFailure;
1825
- if (breakerIsFailure !== void 0 && typeof breakerIsFailure !== "function") {
1826
- throw new AutotaskConfigError("circuitBreaker.isFailure must be a function");
1827
- }
1828
- return {
1829
- enabled: breakerEnabled,
1830
- failureWindowMs: breakerWindowMs,
1831
- failureThreshold: breakerThreshold,
1832
- openTimeoutMs: breakerOpenTimeoutMs,
1833
- successesToClose: breakerSuccessesToClose,
1834
- halfOpenProbes: breakerHalfOpenProbes,
1835
- store: breakerStore,
1836
- isFailure: breakerIsFailure
1231
+ defaultMs: cooldownDefaultMs
1837
1232
  };
1838
1233
  }
1839
1234
  function resolveResolution(config, agent) {
@@ -1851,42 +1246,43 @@ function resolveResolution(config, agent) {
1851
1246
  }
1852
1247
  return { maxScanRecords, maxScanPages, scanOnMiss };
1853
1248
  }
1249
+ var FIELD_CACHE_MAX_ENTRIES = 256;
1854
1250
  function resolveCaches(config) {
1855
- const cacheBlock = config.cache === false || config.cache === void 0 ? void 0 : config.cache;
1856
- resolveReadCacheStore(cacheBlock);
1857
- const fieldCacheBlock = config.fieldCache === false || config.fieldCache === void 0 ? void 0 : config.fieldCache;
1858
- const resourceNameCacheBlock = config.resourceNameCache === false || config.resourceNameCache === void 0 ? void 0 : config.resourceNameCache;
1859
- const readCache = config.cache === false ? void 0 : cacheBlock?.store ?? buildReadCache(config);
1860
- const fieldCache = config.fieldCache === false ? void 0 : new FieldCache(
1861
- fieldCacheBlock?.ttlMs ?? DEFAULT_FIELD_CACHE_TTL_MS,
1862
- fieldCacheBlock?.maxEntities ?? FIELD_CACHE_MAX_ENTITIES
1863
- );
1864
- const resourceNameCache = config.resourceNameCache === false ? void 0 : new ResourceNameCache(
1865
- resourceNameCacheBlock?.ttlMs ?? DEFAULT_RESOURCE_NAME_CACHE_TTL_MS,
1866
- resourceNameCacheBlock?.maxEntries ?? RESOURCE_NAME_CACHE_MAX_ENTRIES
1867
- );
1868
- return { readCache, fieldCache, resourceNameCache };
1869
- }
1870
- function resolveReadCacheStore(cacheBlock) {
1871
- if (cacheBlock === void 0 || cacheBlock === false || cacheBlock.store === void 0) return;
1872
- if (!(cacheBlock.store instanceof ReadCache)) {
1873
- throw new AutotaskConfigError(
1874
- "cache.store must be a ReadCache instance (import { ReadCache } from the SDK; the pool supplies its own)"
1875
- );
1251
+ for (const removed of ["fieldCache", "resourceNameCache"]) {
1252
+ if (removed in config) {
1253
+ throw new AutotaskConfigError(
1254
+ `${removed} was removed in 0.40.0: use cache: false (every channel off) or cache: { ttlMs?, fieldTtlMs? }`
1255
+ );
1256
+ }
1876
1257
  }
1877
- if (cacheBlock.ttlMs !== void 0 || cacheBlock.perResourceTtlMs !== void 0) {
1878
- throw new AutotaskConfigError(
1879
- "cache.store cannot be combined with cache.ttlMs or cache.perResourceTtlMs \u2014 the supplied ReadCache instance owns its TTLs"
1880
- );
1258
+ const block = config.cache;
1259
+ if (block === false) return {};
1260
+ if (block?.store !== void 0) {
1261
+ if (!(block.store instanceof TtlCache)) {
1262
+ throw new AutotaskConfigError("cache.store must be a TtlCache instance (import { TtlCache } from the SDK; the pool supplies its own)");
1263
+ }
1264
+ if (block.ttlMs !== void 0) {
1265
+ throw new AutotaskConfigError("cache.store cannot be combined with cache.ttlMs: the supplied instance owns its TTL");
1266
+ }
1881
1267
  }
1268
+ return {
1269
+ readCache: block?.store ?? buildReadCache(config),
1270
+ fieldCache: new TtlCache(ttlOption(block?.fieldTtlMs, DEFAULT_FIELD_CACHE_TTL_MS, "cache.fieldTtlMs"), {
1271
+ maxEntries: FIELD_CACHE_MAX_ENTRIES
1272
+ })
1273
+ };
1274
+ }
1275
+ function ttlOption(value, fallback, name) {
1276
+ const ms = value ?? fallback;
1277
+ if (!Number.isInteger(ms) || ms <= 0) {
1278
+ throw new AutotaskConfigError(`${name} must be a positive integer (got ${String(ms)})`);
1279
+ }
1280
+ return ms;
1882
1281
  }
1883
1282
  function buildReadCache(config) {
1884
1283
  if (config.cache === false) return void 0;
1885
- const cacheBlock = config.cache === void 0 ? void 0 : config.cache;
1886
- return new ReadCache(
1887
- cacheBlock?.ttlMs ?? DEFAULT_READ_CACHE_TTL_MS,
1888
- { ...DEFAULT_PER_RESOURCE_TTL_MS, ...cacheBlock?.perResourceTtlMs }
1889
- );
1284
+ const ttlMs = ttlOption(config.cache?.ttlMs, DEFAULT_READ_CACHE_TTL_MS, "cache.ttlMs");
1285
+ return new TtlCache(ttlMs, { ttlFor: (key) => readTtlFor(key, ttlMs) });
1890
1286
  }
1891
1287
  function resolveConfig(config) {
1892
1288
  if (config === null || typeof config !== "object") {
@@ -1899,7 +1295,6 @@ function resolveConfig(config) {
1899
1295
  const limits = resolveLimits(config, agent);
1900
1296
  const rateLimit = resolveRateLimit(config, agent);
1901
1297
  const cooldown = resolveCooldown(config);
1902
- const circuitBreaker = resolveCircuitBreaker(config);
1903
1298
  const resolution = resolveResolution(config, agent);
1904
1299
  const redactPersonalData = config.redactPersonalData ?? true;
1905
1300
  const caches = resolveCaches(config);
@@ -1924,7 +1319,6 @@ function resolveConfig(config) {
1924
1319
  logger,
1925
1320
  rateLimit,
1926
1321
  cooldown,
1927
- circuitBreaker,
1928
1322
  resolution,
1929
1323
  onAudit: config.onAudit,
1930
1324
  redactPersonalData,
@@ -2311,7 +1705,7 @@ function maintenanceProbe(text) {
2311
1705
  return Buffer.from(text, "utf8").subarray(0, MAINTENANCE_PROBE_BYTES).toString("utf8");
2312
1706
  }
2313
1707
  function looksLikeMaintenanceText(text) {
2314
- return /maintenance|temporarily unavailable|service unavailable|outage|downtime|down for/i.test(
1708
+ return /maintenance|outage|downtime|down for/i.test(
2315
1709
  maintenanceProbe(text)
2316
1710
  );
2317
1711
  }
@@ -16433,112 +15827,30 @@ function unwrapQueryCount(body, operation) {
16433
15827
  return body.queryCount;
16434
15828
  }
16435
15829
  function unwrapOperation(body, operation) {
16436
- const value = isRecord2(body) ? body.itemId !== void 0 ? body.itemId : body.id : void 0;
16437
- const idValue = toIdentifierId(value);
16438
- if (idValue === void 0) {
16439
- const err = new AutotaskError(
16440
- "Expected OperationResultModel { itemId } (or { id }); got a different shape",
16441
- { code: "INVALID_RESPONSE", category: "server", operation, suggestedAction: INVALID_SHAPE_ACTION }
16442
- );
16443
- attachEmptyReasonDetails(err);
16444
- throw err;
16445
- }
16446
- return { id: idValue };
16447
- }
16448
- function toIdentifierId(value) {
16449
- if (typeof value === "number" && Number.isInteger(value)) return value;
16450
- if (typeof value === "string" && /^\d+$/.test(value.trim())) {
16451
- const trimmed = value.trim();
16452
- const parsed = Number.parseInt(trimmed, 10);
16453
- return Number.isSafeInteger(parsed) ? parsed : trimmed;
16454
- }
16455
- return void 0;
16456
- }
16457
- function passthrough(body) {
16458
- return body;
16459
- }
16460
-
16461
- // src/latest-count-cache.ts
16462
- var LATEST_COUNT_CACHE_TTL_MS = 3e4;
16463
- var LATEST_COUNT_CACHE_MAX_ENTRIES = 4096;
16464
- var LatestCountCache = class {
16465
- /** The TTL in ms. */
16466
- ttlMs;
16467
- /** The entry bound (applies to STORED entries). */
16468
- maxEntries;
16469
- store = /* @__PURE__ */ new Map();
16470
- /** The invalidation epoch (the `ReadCache` pattern — issue #139): bumped
16471
- * by `clear()`; capture it before a wire read and pass it to `set` so a
16472
- * probe in flight across a write cannot re-store its stale answer. */
16473
- epochCounter = 0;
16474
- constructor(ttlMs, maxEntries = LATEST_COUNT_CACHE_MAX_ENTRIES) {
16475
- if (!Number.isInteger(ttlMs) || ttlMs <= 0) {
16476
- throw new AutotaskConfigError(`latestCountCache.ttlMs must be a positive integer (got ${String(ttlMs)})`);
16477
- }
16478
- if (!Number.isInteger(maxEntries) || maxEntries <= 0) {
16479
- throw new AutotaskConfigError(`latestCountCache.maxEntries must be a positive integer (got ${String(maxEntries)})`);
16480
- }
16481
- this.ttlMs = ttlMs;
16482
- this.maxEntries = maxEntries;
16483
- }
16484
- /** The composite key: (resource plan key, canonical filter serialisation)
16485
- * — the `\u0000` separator is unencodable in a filter value, so no two
16486
- * (resource, conditions) pairs collide. */
16487
- static key(resourceKey, conditions) {
16488
- return `${resourceKey}\0${JSON.stringify(conditions ?? [])}`;
16489
- }
16490
- /** The live entry's count, or `undefined` (absent OR expired — an expired
16491
- * entry is purged lazily on this read). */
16492
- get(key) {
16493
- const entry = this.store.get(key);
16494
- if (entry === void 0) return void 0;
16495
- if (entry.expiresAt <= Date.now()) {
16496
- this.store.delete(key);
16497
- return void 0;
16498
- }
16499
- return entry.value;
16500
- }
16501
- /** The invalidation epoch: bumped by `clear()`; capture it before a wire
16502
- * read and pass it to `set` so a probe in flight across a write cannot
16503
- * re-store its stale answer (issue #139, the `ReadCache` pattern). */
16504
- get epoch() {
16505
- return this.epochCounter;
16506
- }
16507
- /** Store a SUCCESSFUL plain-number count under `key`, live for `ttlMs`.
16508
- * `epoch` is the invalidation epoch the caller captured BEFORE its wire
16509
- * read: a probe that straddled a `clear()` (a write) is dropped, never
16510
- * re-stored with its pre-write body (issue #139). Past the cap: purge
16511
- * expired entries first, then evict the oldest-inserted (Map iteration
16512
- * order = insertion order). */
16513
- set(key, value, epoch = this.epochCounter) {
16514
- if (epoch !== this.epochCounter) return;
16515
- if (!Number.isFinite(value)) return;
16516
- const entry = { value, expiresAt: Date.now() + this.ttlMs };
16517
- if (!this.store.has(key) && this.store.size >= this.maxEntries) {
16518
- for (const [k, e] of this.store) {
16519
- if (e.expiresAt <= Date.now()) this.store.delete(k);
16520
- }
16521
- if (this.store.size >= this.maxEntries) {
16522
- const oldest = this.store.keys().next();
16523
- if (!oldest.done) this.store.delete(oldest.value);
16524
- }
16525
- }
16526
- this.store.set(key, entry);
16527
- }
16528
- /** Drop one entry (absent = no-op). Issue #157: the stale-LOW recovery
16529
- * deletes the cached total before its one fresh wire re-probe, so the
16530
- * re-probe cannot be served by the entry it is meant to replace. */
16531
- delete(key) {
16532
- this.store.delete(key);
15830
+ const value = isRecord2(body) ? body.itemId !== void 0 ? body.itemId : body.id : void 0;
15831
+ const idValue = toIdentifierId(value);
15832
+ if (idValue === void 0) {
15833
+ const err = new AutotaskError(
15834
+ "Expected OperationResultModel { itemId } (or { id }); got a different shape",
15835
+ { code: "INVALID_RESPONSE", category: "server", operation, suggestedAction: INVALID_SHAPE_ACTION }
15836
+ );
15837
+ attachEmptyReasonDetails(err);
15838
+ throw err;
16533
15839
  }
16534
- /** Clear every entry (a real write through the owning client — the
16535
- * write-then-read re-fetch rule) and bump the invalidation epoch: a
16536
- * `set` captured before this `clear` is discarded (issue #139). */
16537
- clear() {
16538
- this.epochCounter += 1;
16539
- this.store.clear();
15840
+ return { id: idValue };
15841
+ }
15842
+ function toIdentifierId(value) {
15843
+ if (typeof value === "number" && Number.isInteger(value)) return value;
15844
+ if (typeof value === "string" && /^\d+$/.test(value.trim())) {
15845
+ const trimmed = value.trim();
15846
+ const parsed = Number.parseInt(trimmed, 10);
15847
+ return Number.isSafeInteger(parsed) ? parsed : trimmed;
16540
15848
  }
16541
- };
15849
+ return void 0;
15850
+ }
15851
+ function passthrough(body) {
15852
+ return body;
15853
+ }
16542
15854
 
16543
15855
  // src/http/body.ts
16544
15856
  async function readBodyText(res, max, what, ctx) {
@@ -16578,120 +15890,7 @@ function bodySnippet(text, redactPersonalData) {
16578
15890
  return redactResponseBody(bytes, { redactPersonalData });
16579
15891
  }
16580
15892
 
16581
- // src/http/breaker-budget.ts
16582
- function cooldownRefusal(store, tenantKey, ctx) {
16583
- const deadline = store.get(tenantKey);
16584
- if (deadline === void 0) return void 0;
16585
- const remainingMs = deadline - Date.now();
16586
- if (remainingMs > 0) {
16587
- const seconds = Math.ceil(remainingMs / 1e3);
16588
- const err = new RateLimitError(
16589
- `Tenant is in a rate-limit cooldown; the call was NOT sent. ${seconds}s remain \u2014 do not retry before then, and narrow the query (filter/includeFields) before retrying.`,
16590
- {
16591
- ...ctx,
16592
- code: "RATE_LIMITED_COOLDOWN",
16593
- retryable: false,
16594
- suggestedAction: `Wait ${seconds}s (per-tenant 429 cooldown) and retry with a narrower query; the call was not sent and consumed no vendor budget.`
16595
- }
16596
- );
16597
- err.retryAfter = seconds;
16598
- err.notSent = true;
16599
- return err;
16600
- }
16601
- store.delete(tenantKey);
16602
- return void 0;
16603
- }
16604
- function evaluateBreakerGate(breaker, key, ctx) {
16605
- const now = Date.now();
16606
- const st = breaker.store.get(key);
16607
- if (st !== void 0 && st.openedAt !== null) {
16608
- const openUntil = st.openedAt + breaker.openTimeoutMs;
16609
- if (now < openUntil) {
16610
- const remainingMs = openUntil - now;
16611
- const seconds = Math.ceil(remainingMs / 1e3);
16612
- const err = new CircuitBreakerError(
16613
- `The circuit breaker for ${key} is open; the call was NOT sent. ${seconds}s remain \u2014 retry the same call after the wait (a host-scoped vendor fault, not the request).`,
16614
- {
16615
- ...ctx,
16616
- details: { state: "open", retryAfterMs: remainingMs, failureCount: st.failures.length },
16617
- suggestedAction: `Wait ${seconds}s (the circuit is open for ${key}) and retry the SAME call; the call was not sent and consumed no vendor budget.`
16618
- }
16619
- );
16620
- err.retryAfter = seconds;
16621
- err.notSent = true;
16622
- return { refusal: err };
16623
- }
16624
- if (st.probes >= breaker.halfOpenProbes) {
16625
- const err = new CircuitBreakerError(
16626
- `The circuit breaker for ${key} is half-open and its probes are in flight; the call was NOT sent \u2014 retry once a probe settles.`,
16627
- {
16628
- ...ctx,
16629
- details: { state: "half-open", retryAfterMs: 0, failureCount: st.failures.length },
16630
- suggestedAction: "A half-open probe is settling; retry shortly \u2014 the call was not sent and consumed no vendor budget."
16631
- }
16632
- );
16633
- err.notSent = true;
16634
- return { refusal: err };
16635
- }
16636
- const admitted = { ...st, probes: st.probes + 1 };
16637
- breaker.store.set(key, admitted);
16638
- return { probe: true, probeWindow: admitted.windowOpenedAt ?? void 0 };
16639
- }
16640
- return { probe: false };
16641
- }
16642
- function recordSuccess(breaker, key, probe, probeWindow, logger) {
16643
- const st = breaker.store.get(key);
16644
- if (st === void 0 || st.openedAt === null) return;
16645
- if (probe && probeWindow !== void 0 && st.windowOpenedAt !== probeWindow) return;
16646
- const next = {
16647
- failures: st.failures,
16648
- openedAt: st.openedAt,
16649
- successes: st.successes + 1,
16650
- probes: probe ? Math.max(0, st.probes - 1) : st.probes,
16651
- windowOpenedAt: st.windowOpenedAt
16652
- // a success never moves the window identity
16653
- };
16654
- if (next.successes >= breaker.successesToClose) {
16655
- breaker.store.delete(key);
16656
- logger.warn?.(
16657
- `[autotask] circuit breaker CLOSED for ${key} (${next.successes} probe successes)`,
16658
- void 0
16659
- );
16660
- return;
16661
- }
16662
- breaker.store.set(key, next);
16663
- }
16664
- function recordFailure(breaker, key, probe, probeWindow, logger, correlationId) {
16665
- const now = Date.now();
16666
- const st = breaker.store.get(key) ?? { failures: [], openedAt: null, successes: 0, probes: 0, windowOpenedAt: null };
16667
- if (probe && probeWindow !== void 0 && st.openedAt !== null && st.windowOpenedAt !== probeWindow) return;
16668
- if (st.openedAt === null) {
16669
- const failures = [...st.failures.filter((t) => t > now - breaker.failureWindowMs), now];
16670
- if (failures.length >= breaker.failureThreshold) {
16671
- breaker.store.set(key, { failures, openedAt: now, successes: 0, probes: 0, windowOpenedAt: now });
16672
- logger.warn?.(
16673
- `[autotask] circuit breaker OPEN for ${key} (${failures.length} counted failures in ${Math.round(breaker.failureWindowMs / 1e3)}s) \u2014 refusing locally for ${Math.round(breaker.openTimeoutMs / 1e3)}s`,
16674
- correlationId
16675
- );
16676
- return;
16677
- }
16678
- breaker.store.set(key, { ...st, failures });
16679
- return;
16680
- }
16681
- breaker.store.set(key, {
16682
- failures: st.failures,
16683
- openedAt: now,
16684
- successes: 0,
16685
- probes: probe ? Math.max(0, st.probes - 1) : st.probes,
16686
- windowOpenedAt: st.windowOpenedAt
16687
- });
16688
- }
16689
- function settleProbe(breaker, key, probeWindow) {
16690
- const st = breaker.store.get(key);
16691
- if (st === void 0 || st.openedAt === null || st.probes === 0) return;
16692
- if (probeWindow !== void 0 && st.windowOpenedAt !== probeWindow) return;
16693
- breaker.store.set(key, { ...st, probes: st.probes - 1 });
16694
- }
15893
+ // src/http/limits.ts
16695
15894
  var HourlyBudget = class {
16696
15895
  constructor(perHour, profile) {
16697
15896
  this.perHour = perHour;
@@ -16878,17 +16077,10 @@ var HttpClient = class {
16878
16077
  timeoutMs;
16879
16078
  /** Bounded client-scan caps for resolution (section 19.2; per-client). */
16880
16079
  resolution;
16881
- /** Single-record read cache (issue #80: the default instance when `cache` is absent; undefined only when the user set `false` explicitly). */
16080
+ /** Record-read cache (absent only for `cache: false`; issue #286). */
16882
16081
  readCache;
16883
- /** Field-metadata cache for the entityInformation trio (issue #80: the default instance when `fieldCache` is absent; undefined only when the user set `false` explicitly). */
16082
+ /** Field-metadata cache for the entityInformation trio (absent only for `cache: false`). */
16884
16083
  fieldCache;
16885
- /** Resource-name cache for `operations.expandResourceNames` (issue #80: the default instance when `resourceNameCache` is absent; undefined only when the user set `false` explicitly, issue #65). */
16886
- resourceNameCache;
16887
- /** The `latest` walk's count-probe cache (issue #127: the short-TTL
16888
- * per-client count cache — ALWAYS on, process-internal: no config
16889
- * surface, no served keys; the plain `count` op and `operations.aggregate`
16890
- * bypass it by construction and promise fresh totals). */
16891
- latestCountCache;
16892
16084
  /** Resolved update fallback gate (issue #34; OFF by default). */
16893
16085
  update;
16894
16086
  auth;
@@ -16901,8 +16093,8 @@ var HttpClient = class {
16901
16093
  hourly;
16902
16094
  /** FIFO semaphore bounding in-flight requests to `maxConcurrent`. */
16903
16095
  semaphore;
16904
- /** Tenant 429 cooldown gate store (undefined when the gate is disabled). */
16905
- cooldownStore;
16096
+ /** Tenant 429 cooldown gate (issue #6; ON by default). */
16097
+ cooldownEnabled;
16906
16098
  cooldownMaxMs;
16907
16099
  cooldownDefaultMs;
16908
16100
  /** The live base URL (issue #43 — the `baseUrl` getter's backing field;
@@ -16921,18 +16113,9 @@ var HttpClient = class {
16921
16113
  * Gates the issue-#43 re-point target: a refused host is a discovery
16922
16114
  * fault (the original 401 propagates byte-identically, zero wire). */
16923
16115
  hostPolicy;
16924
- /** The gate key for this client's tenant (lowercased userName + host).
16925
- * Re-derived on a zone re-point (issue #43 — the re-pointed host starts
16926
- * with fresh per-host state). */
16116
+ /** The cooldown key (`user@host`) and the maintenance-gate key (host); re-derived on a zone re-point (issue #43). */
16927
16117
  tenantKey;
16928
- /** The host circuit breaker settings (issue #26; undefined when the
16929
- * breaker is off — the default, in which case the gate/recording sites
16930
- * are skipped and no store entry is ever written). */
16931
- breaker;
16932
- /** The breaker key for this client's host (lowercased host of the base
16933
- * URL — host-only: vendor health is host-scoped, issue #26). Re-derived
16934
- * on a zone re-point (issue #43). */
16935
- breakerKey;
16118
+ hostKey;
16936
16119
  logger;
16937
16120
  /** Response redaction policy (the INV-A1 hotfix; PII/CONFIDENTIAL default on, SECRET always).
16938
16121
  * Public read so the single dry-run envelope builder (base.ts `buildDryRunResult`)
@@ -16949,8 +16132,6 @@ var HttpClient = class {
16949
16132
  this.resolution = config.resolution;
16950
16133
  this.readCache = config.readCache;
16951
16134
  this.fieldCache = config.fieldCache;
16952
- this.resourceNameCache = config.resourceNameCache;
16953
- this.latestCountCache = new LatestCountCache(LATEST_COUNT_CACHE_TTL_MS);
16954
16135
  this.update = config.update;
16955
16136
  this.zone = config.zone;
16956
16137
  this.reResolveZoneOn401 = config.reResolveZoneOn401;
@@ -16967,20 +16148,11 @@ var HttpClient = class {
16967
16148
  this.maintenancePollMs = config.maintenancePollMs;
16968
16149
  this.maxResponseBytes = config.maxResponseBytes;
16969
16150
  this.hourly = config.rateLimit?.perHour === void 0 ? void 0 : new HourlyBudget(config.rateLimit.perHour, config.profile);
16970
- this.tenantKey = buildTenantKey(config.userName, config.baseUrl);
16971
- this.cooldownStore = config.cooldown.enabled ? config.cooldown.store ?? defaultCooldownStore() : void 0;
16151
+ this.tenantKey = tenantKey(config.userName, config.baseUrl);
16152
+ this.hostKey = hostKey(config.baseUrl);
16153
+ this.cooldownEnabled = config.cooldown.enabled;
16972
16154
  this.cooldownMaxMs = config.cooldown.maxMs;
16973
16155
  this.cooldownDefaultMs = config.cooldown.defaultMs;
16974
- this.breakerKey = buildBreakerKey(config.baseUrl);
16975
- this.breaker = config.circuitBreaker.enabled ? {
16976
- failureWindowMs: config.circuitBreaker.failureWindowMs,
16977
- failureThreshold: config.circuitBreaker.failureThreshold,
16978
- openTimeoutMs: config.circuitBreaker.openTimeoutMs,
16979
- successesToClose: config.circuitBreaker.successesToClose,
16980
- halfOpenProbes: config.circuitBreaker.halfOpenProbes,
16981
- store: config.circuitBreaker.store ?? defaultCircuitBreakerStore(),
16982
- isFailure: config.circuitBreaker.isFailure ?? isBreakerFailure
16983
- } : void 0;
16984
16156
  this.maxConcurrent = config.maxConcurrent;
16985
16157
  this.semaphore = new Semaphore(config.maxConcurrent);
16986
16158
  this.timeoutMs = config.timeoutMs;
@@ -17012,11 +16184,9 @@ var HttpClient = class {
17012
16184
  }
17013
16185
  /**
17014
16186
  * Issue #43: re-point the client to the tenant's newly resolved zone
17015
- * base. The transport's PER-HOST state is RE-DERIVED, so the re-pointed
17016
- * host starts FRESH: no cooldown/breaker/tenant-rate inheritance from
17017
- * the stale host (conservative — the stale host's armed entries stay in
17018
- * the shared stores for the other clients that still talk to it; nothing
17019
- * is copied across). The configured base (config.baseUrl) is untouched;
16187
+ * base. The gate keys are RE-DERIVED, so the re-pointed host starts
16188
+ * fresh: no cooldown/maintenance inheritance from the stale host (its
16189
+ * entries stay for the other clients that still talk to it). The configured base (config.baseUrl) is untouched;
17020
16190
  * the LIVE base is `baseUrl` (the getter over liveBaseUrl), and the
17021
16191
  * re-point is logged (a transport fact — the success path is unchanged,
17022
16192
  * no envelope change).
@@ -17024,53 +16194,13 @@ var HttpClient = class {
17024
16194
  repointZoneBase(to) {
17025
16195
  const from = this.liveBaseUrl;
17026
16196
  this.liveBaseUrl = to;
17027
- this.tenantKey = buildTenantKey(this.auth.userName, to);
17028
- this.breakerKey = buildBreakerKey(to);
16197
+ this.tenantKey = tenantKey(this.auth.userName, to);
16198
+ this.hostKey = hostKey(to);
17029
16199
  this.logger.warn?.(
17030
16200
  `[autotask] zone re-point ${from} -> ${to} (a 401 on the stale zone base; the vendor's unauthenticated zone discovery named the tenant's current zone) \u2014 retrying the request once against the new base`,
17031
16201
  void 0
17032
16202
  );
17033
16203
  }
17034
- /**
17035
- * Breaker success recording (issue #26). A probe admitted on one host must
17036
- * never record onto another: if the call re-pointed (issue #43) the
17037
- * outcome was measured on a different host — void the probe (the admitted
17038
- * budget on the original host dangles for the rest of the open period;
17039
- * bounded, conservative, nothing crosses hosts).
17040
- */
17041
- recordBreakerSuccess(s) {
17042
- const { breakerProbe: probe, breakerProbeKey: probeKey, breakerProbeWindow: probeWindow } = s;
17043
- const breaker = this.breaker;
17044
- if (breaker === void 0) return;
17045
- if (probe && (probeKey === void 0 || probeKey !== this.breakerKey)) return;
17046
- recordSuccess(breaker, probe && probeKey !== void 0 ? probeKey : this.breakerKey, probe, probeWindow, this.logger);
17047
- }
17048
- /** Breaker failure recording (issue #26); same host-pinning as the success recorder (issue #43). */
17049
- recordBreakerFailure(s) {
17050
- const { breakerProbe: probe, breakerProbeKey: probeKey, breakerProbeWindow: probeWindow, correlationId } = s;
17051
- const breaker = this.breaker;
17052
- if (breaker === void 0) return;
17053
- if (probe && (probeKey === void 0 || probeKey !== this.breakerKey)) return;
17054
- recordFailure(breaker, probe && probeKey !== void 0 ? probeKey : this.breakerKey, probe, probeWindow, this.logger, correlationId);
17055
- }
17056
- /**
17057
- * Breaker probe settlement for a NON-COUNTED outcome (issue #262): the
17058
- * failure predicate said the outcome is not a service failure (any 4xx,
17059
- * ABORTED, EMPTY_RESPONSE, INVALID_RESPONSE, REDIRECT_BLOCKED, the
17060
- * deterministic validation 500), so nothing is counted and the open
17061
- * period is NOT re-armed — but the probe SETTLED, so its admitted
17062
- * half-open slot is released (the contract in `circuit-breaker.ts`: every
17063
- * probe completion decrements `probes`). Same host-pinning as the
17064
- * recorders (issue #43): a re-pointed probe is voided, never settled
17065
- * cross-host.
17066
- */
17067
- settleBreakerProbe(s) {
17068
- const { breakerProbe: probe, breakerProbeKey: probeKey, breakerProbeWindow: probeWindow } = s;
17069
- const breaker = this.breaker;
17070
- if (breaker === void 0 || !probe) return;
17071
- if (probeKey === void 0 || probeKey !== this.breakerKey) return;
17072
- settleProbe(breaker, probeKey, probeWindow);
17073
- }
17074
16204
  // ---- per-call helpers ---------------------------------------------------
17075
16205
  /** The caller's signal wins over the deadline when both fired. */
17076
16206
  interrupted(s) {
@@ -17109,10 +16239,18 @@ var HttpClient = class {
17109
16239
  * `maintenanceMaxWaitMs` from the FIRST such response (one budget shared
17110
16240
  * by the 2xx-page and any-status sites), polling `maintenancePollMs`, a
17111
16241
  * fresh per-attempt deadline after each wait; does not consume
17112
- * `maxRetries`. True when a wait happened (loop again); false when the
17113
- * budget is spent (`maintenanceBudgetSpent` is set).
16242
+ * `maxRetries`. Only the call that owns the zone's probe slot waits (one
16243
+ * prober per zone); any other call gets false at once. True when a wait
16244
+ * happened (loop again); false when the budget is spent
16245
+ * (`maintenanceBudgetSpent` is set) or another call owns the slot.
17114
16246
  */
17115
16247
  async waitOutMaintenance(s, statusLabel) {
16248
+ if (s.maintenanceMaxWaitMs <= 0) return false;
16249
+ if (s.maintenanceProbe === void 0) {
16250
+ const gate = claimMaintenanceProbe(this.hostKey);
16251
+ if (gate === void 0) return false;
16252
+ s.maintenanceProbe = { host: this.hostKey, gate };
16253
+ }
17116
16254
  const now = Date.now();
17117
16255
  s.firstMaintenanceAt ??= now;
17118
16256
  const remaining = s.maintenanceMaxWaitMs - (now - s.firstMaintenanceAt);
@@ -17148,6 +16286,41 @@ var HttpClient = class {
17148
16286
  err.suggestedAction = maintenanceExhaustedAction(s.maintenanceMaxWaitMs, s.maintenanceWaits);
17149
16287
  }
17150
16288
  }
16289
+ /**
16290
+ * Issue #285: the call itself received the maintenance page and will not
16291
+ * (or may not) wait it out — the same typed `MAINTENANCE` the gate's
16292
+ * refusals carry, so a consumer maps one code. Unlike a refusal the call
16293
+ * WAS sent (`httpStatus` set, no `notSent`). A mutation answered at a
16294
+ * non-2xx status (review F1) is not retryable: a proxy can serve that page
16295
+ * after forwarding the write, so the outcome is unknown.
16296
+ */
16297
+ maintenancePageError(s, status, contentType, text) {
16298
+ const { method, opts, ctx } = s;
16299
+ const since = new Date(maintenanceSince(this.hostKey) ?? Date.now()).toISOString();
16300
+ const unknownWrite = (status < 200 || status >= 300) && !s.retriable5xx;
16301
+ const err = new MaintenanceError(
16302
+ `Zone ${this.hostKey} answered ${method} ${opts.path} with its maintenance page (HTTP ${status}; window since ${since})`,
16303
+ {
16304
+ ...ctx,
16305
+ httpStatus: status,
16306
+ retryable: !unknownWrite,
16307
+ details: {
16308
+ since,
16309
+ retryAfterMs: s.maintenancePollMs,
16310
+ httpStatus: status,
16311
+ contentType,
16312
+ bodySnippet: bodySnippet(text, this.redactPersonalData),
16313
+ maintenanceDetected: true
16314
+ },
16315
+ suggestedAction: unknownWrite ? `A maintenance-shaped page answered ${method} ${opts.path} (HTTP ${status}); it was NOT waited out or re-sent \u2014 a non-2xx edge page can arrive after the request was forwarded, so verify the record before re-issuing (only a GET or an explicitly idempotent-flagged call waits this window out).` : `The Autotask zone is in its maintenance window (since ${since}); retry after the window (windows usually last 30-90 min).`
16316
+ }
16317
+ );
16318
+ err.retryAfter = Math.max(1, Math.ceil(s.maintenancePollMs / 1e3));
16319
+ const action = err.suggestedAction;
16320
+ this.stampMaintenance(s, err);
16321
+ if (unknownWrite) err.suggestedAction = action;
16322
+ return err;
16323
+ }
17151
16324
  // ---- pre-send gates -----------------------------------------------------
17152
16325
  auditNotSent(s, errorCode) {
17153
16326
  this.emitAudit({
@@ -17162,39 +16335,23 @@ var HttpClient = class {
17162
16335
  });
17163
16336
  }
17164
16337
  /**
17165
- * Tenant 429 cooldown gate (issue #6): a 429 armed the gate for this
17166
- * tenant — fail LOCALLY (before the semaphore, the hourly limiter and
17167
- * fetch: zero upstream calls) until the deadline passes.
17168
- */
17169
- gateCooldown(s) {
17170
- if (this.cooldownStore === void 0 || s.opts.bypassCooldown) return;
17171
- const err = cooldownRefusal(this.cooldownStore, this.tenantKey, s.ctx);
17172
- if (err === void 0) return;
17173
- if (s.callerSignal?.aborted) throw this.interrupted(s);
17174
- this.auditNotSent(s, "RATE_LIMITED_COOLDOWN");
17175
- throw err;
17176
- }
17177
- /**
17178
- * Host circuit breaker gate (issue #26): the SAME pre-send slot as the
17179
- * #6 cooldown gate (cooldown first): OUTSIDE the retry loop, before the
17180
- * hourly limiter, the semaphore and fetch — a refusal makes zero fetches,
17181
- * consumes no hourly stamp and no concurrency slot.
17182
- * `thresholdInformation.get()` bypasses the REFUSAL
17183
- * (`bypassCircuitBreaker`) but its outcome is still recorded.
16338
+ * The pre-send gates (OUTSIDE the retry loop, before the hourly limiter,
16339
+ * the semaphore and fetch: a refusal makes zero fetches). The tenant 429
16340
+ * cooldown (issue #6; `thresholdInformation.get()` bypasses it), then the
16341
+ * zone maintenance gate (issue #285), which admits one probe per poll
16342
+ * interval while open. An already-aborted caller still gets the abort error.
17184
16343
  */
17185
- gateBreaker(s) {
17186
- if (this.breaker === void 0 || s.opts.bypassCircuitBreaker) return;
17187
- if (s.callerSignal?.aborted) throw this.interrupted(s);
17188
- const verdict = evaluateBreakerGate(this.breaker, this.breakerKey, s.ctx);
17189
- if (verdict.refusal !== void 0) {
17190
- this.auditNotSent(s, "CIRCUIT_BREAKER_OPEN");
17191
- throw verdict.refusal;
17192
- }
17193
- if (verdict.probe) {
17194
- s.breakerProbe = true;
17195
- s.breakerProbeKey = this.breakerKey;
17196
- s.breakerProbeWindow = verdict.probeWindow;
16344
+ gate(s) {
16345
+ const cooldown = this.cooldownEnabled && !s.opts.bypassCooldown ? cooldownRefusal(this.tenantKey, s.ctx) : void 0;
16346
+ const verdict = cooldown ?? admitMaintenance(this.hostKey, s.ctx);
16347
+ if (verdict === "send") return;
16348
+ if (!(verdict instanceof AutotaskError)) {
16349
+ s.maintenanceProbe = { host: this.hostKey, gate: verdict };
16350
+ return;
17197
16351
  }
16352
+ if (s.callerSignal?.aborted) throw this.interrupted(s);
16353
+ this.auditNotSent(s, verdict.code);
16354
+ throw verdict;
17198
16355
  }
17199
16356
  // ---- the attempt --------------------------------------------------------
17200
16357
  /**
@@ -17254,7 +16411,7 @@ var HttpClient = class {
17254
16411
  /** Classify a 2xx: empty body, JSON (redacted), or a non-JSON page (maintenance wait / retry / typed error). */
17255
16412
  async handleSuccess(s, res, status, text) {
17256
16413
  const { method, opts, ctx } = s;
17257
- if (this.cooldownStore !== void 0) this.cooldownStore.delete(this.tenantKey);
16414
+ if (this.cooldownEnabled) clearCooldown(this.tenantKey);
17258
16415
  if (text.length === 0) {
17259
16416
  if (s.expectBody) {
17260
16417
  const err = new EmptyResponseError(`Empty ${status} response for ${method} ${opts.path}`, {
@@ -17305,17 +16462,17 @@ var HttpClient = class {
17305
16462
  httpStatus: status,
17306
16463
  suggestedAction: "The zone returned a non-JSON 2xx body; verify baseUrl points at the REST API."
17307
16464
  });
17308
- if (err.code === "UNEXPECTED_CONTENT_TYPE" && s.maintenanceMaxWaitMs > 0 && looksLikeMaintenanceText(text)) {
16465
+ if (s.maintenancePage) {
17309
16466
  if (await this.waitOutMaintenance(s, "")) return RETRY;
17310
- }
17311
- if (err.code === "UNEXPECTED_CONTENT_TYPE" && retriable5xx && s.attempt < s.maxRetries) {
16467
+ throw this.maintenancePageError(s, status, res.headers.get("Content-Type"), text);
16468
+ } else if (err.code === "UNEXPECTED_CONTENT_TYPE" && retriable5xx && s.attempt < s.maxRetries) {
17312
16469
  const retryAfter = parseRetryAfter(res.headers.get("Retry-After"));
17313
16470
  const delay = retryAfter !== void 0 ? retryAfter * 1e3 : backoffDelay(s.attempt);
17314
16471
  if (await this.retryAfterDelay(s, delay, `non-JSON 2xx on ${method} ${opts.path}`)) return RETRY;
17315
16472
  }
17316
16473
  const pageSnippet = typeof err.details?.bodySnippet === "string" ? err.details.bodySnippet : "";
17317
16474
  this.stampMaintenance(s, err);
17318
- if (err.code === "UNEXPECTED_CONTENT_TYPE" && !looksLikeMaintenanceText(text) && isHtmlLike(res.headers.get("Content-Type"), text)) {
16475
+ if (err.code === "UNEXPECTED_CONTENT_TYPE" && !s.maintenancePage && isHtmlLike(res.headers.get("Content-Type"), text)) {
17319
16476
  err.details = { ...err.details ?? {}, maintenancePatternMiss: true };
17320
16477
  this.logger.debug?.(
17321
16478
  `[autotask] non-JSON body did not match the maintenance vocabulary on ${method} ${opts.path}: ${pageSnippet}`,
@@ -17343,15 +16500,15 @@ var HttpClient = class {
17343
16500
  }
17344
16501
  }
17345
16502
  const nonJsonSnippet = nonJsonBody === void 0 ? void 0 : bodySnippet(nonJsonBody, this.redactPersonalData);
17346
- const nonJsonIsMaintenance = nonJsonBody !== void 0 && looksLikeMaintenanceText(nonJsonBody);
16503
+ const nonJsonIsMaintenance = s.maintenancePage;
17347
16504
  const nonJsonIsHtmlCandidate = nonJsonBody !== void 0 && isHtmlLike(res.headers.get("Content-Type"), nonJsonBody);
17348
- const nonJsonMaintenanceMayWait = nonJsonIsMaintenance && s.retriable5xx;
17349
- if (nonJsonBody !== void 0 && s.maintenanceMaxWaitMs > 0 && nonJsonMaintenanceMayWait) {
17350
- if (await this.waitOutMaintenance(s, ` (HTTP ${status})`)) return RETRY;
16505
+ if (nonJsonIsMaintenance) {
16506
+ if (s.retriable5xx && await this.waitOutMaintenance(s, ` (HTTP ${status})`)) return RETRY;
16507
+ throw this.maintenancePageError(s, status, res.headers.get("Content-Type"), text);
17351
16508
  }
17352
16509
  const deterministic500 = status >= 500 && isDeterministicVendor500(parseVendorErrors(body));
17353
16510
  const retryableStatus = status === 429 || status >= 500;
17354
- if (retryableStatus && !deterministic500 && s.attempt < s.maxRetries && (status === 429 ? s.retriable : s.retriable5xx)) {
16511
+ if (retryableStatus && !deterministic500 && !nonJsonIsMaintenance && s.attempt < s.maxRetries && (status === 429 ? s.retriable : s.retriable5xx)) {
17355
16512
  const retryAfter = parseRetryAfter(res.headers.get("Retry-After"));
17356
16513
  const delay = retryAfter !== void 0 ? retryAfter * 1e3 : backoffDelay(s.attempt);
17357
16514
  if (await this.retryAfterDelay(s, delay, `${status} on ${method} ${opts.path}`)) return RETRY;
@@ -17384,10 +16541,7 @@ var HttpClient = class {
17384
16541
  err.correlationId = s.correlationId;
17385
16542
  this.stampMaintenance(s, err);
17386
16543
  if (nonJsonBody !== void 0) {
17387
- if (nonJsonIsMaintenance && !s.retriable5xx) {
17388
- err.details = { ...err.details ?? {}, maintenanceDetected: true };
17389
- err.suggestedAction = `A maintenance-shaped page answered ${method} ${opts.path} (HTTP ${status}); it was NOT waited out or re-sent \u2014 a non-2xx edge page can arrive after the request was forwarded, so verify the record before re-issuing (only a GET or an explicitly idempotent-flagged call waits this window out).`;
17390
- } else if (!nonJsonIsMaintenance && nonJsonIsHtmlCandidate) {
16544
+ if (nonJsonIsHtmlCandidate) {
17391
16545
  err.details = { ...err.details ?? {}, maintenancePatternMiss: true };
17392
16546
  this.logger.debug?.(
17393
16547
  `[autotask] non-JSON body did not match the maintenance vocabulary on ${method} ${opts.path}: ${nonJsonSnippet}`,
@@ -17403,14 +16557,14 @@ var HttpClient = class {
17403
16557
  }
17404
16558
  attachEmptyReasonDetails(err);
17405
16559
  if (err instanceof RateLimitError && retryAfterSecs !== void 0) err.retryAfter = retryAfterSecs;
17406
- if (status === 429 && this.cooldownStore !== void 0) {
16560
+ if (status === 429 && this.cooldownEnabled) {
17407
16561
  const threadThreshold = err.code.toLowerCase() === "itgenatr005";
17408
16562
  const durationMs = cooldownDurationMs(retryAfterSecs, {
17409
16563
  maxMs: this.cooldownMaxMs,
17410
16564
  defaultMs: this.cooldownDefaultMs,
17411
16565
  threadThreshold
17412
16566
  });
17413
- this.cooldownStore.set(this.tenantKey, Date.now() + durationMs);
16567
+ armCooldown(this.tenantKey, Date.now() + durationMs);
17414
16568
  this.logger.warn?.(
17415
16569
  `[autotask] 429 on ${method} ${opts.path} surfaces after ${s.attempt + 1} attempt(s); tenant cooldown armed for ${Math.round(durationMs / 1e3)}s`,
17416
16570
  s.correlationId
@@ -17429,25 +16583,9 @@ var HttpClient = class {
17429
16583
  durationMs: Date.now() - s.started,
17430
16584
  body: s.auditBody
17431
16585
  });
17432
- if (this.breaker !== void 0) {
17433
- try {
17434
- this.recordBreakerSuccess(s);
17435
- } catch {
17436
- }
17437
- }
17438
16586
  }
17439
16587
  onFailure(s, err) {
17440
16588
  const { opts } = s;
17441
- if (this.breaker !== void 0 && err instanceof AutotaskError && err.notSent !== true) {
17442
- try {
17443
- if (this.breaker.isFailure(err)) {
17444
- this.recordBreakerFailure(s);
17445
- } else if (s.breakerProbe) {
17446
- this.settleBreakerProbe(s);
17447
- }
17448
- } catch {
17449
- }
17450
- }
17451
16589
  this.emitAudit({
17452
16590
  correlationId: s.correlationId,
17453
16591
  operation: opts.operation,
@@ -17464,7 +16602,7 @@ var HttpClient = class {
17464
16602
  const drift = err.details?.deterministic === true || err.code === "INVALID_RESPONSE" && META_TRIO_VERBS.has(verb);
17465
16603
  if (drift && op !== void 0) {
17466
16604
  const dot = op.indexOf(".");
17467
- if (dot > 0) this.fieldCache.invalidate(op.slice(0, dot));
16605
+ if (dot > 0) this.fieldCache.invalidate(`${op.slice(0, dot)}:`);
17468
16606
  }
17469
16607
  }
17470
16608
  }
@@ -17472,12 +16610,6 @@ var HttpClient = class {
17472
16610
  invalidateAfterWrite(opts) {
17473
16611
  if (opts.method === "GET" || opts.idempotent === true && /\/query(\/|\?|$)/.test(opts.path)) return;
17474
16612
  this.readCache?.clear();
17475
- this.latestCountCache.clear();
17476
- const nameOp = typeof opts.operation === "string" ? opts.operation : void 0;
17477
- const nameDot = nameOp !== void 0 ? nameOp.indexOf(".") : -1;
17478
- if (this.resourceNameCache !== void 0 && nameOp !== void 0 && nameDot > 0 && nameOp.slice(0, nameDot) === "resources") {
17479
- this.resourceNameCache.clear();
17480
- }
17481
16613
  }
17482
16614
  /**
17483
16615
  * One request: build URL/headers, apply the whole-call deadline, retry
@@ -17544,22 +16676,23 @@ var HttpClient = class {
17544
16676
  lastStatus: void 0,
17545
16677
  zoneRetry: void 0,
17546
16678
  attempt: 0,
17547
- breakerProbe: false,
17548
- breakerProbeKey: void 0,
17549
- breakerProbeWindow: void 0,
16679
+ maintenanceProbe: void 0,
16680
+ maintenancePage: false,
17550
16681
  // Armed LAST in the literal: nothing after this can throw, and the single
17551
16682
  // try/finally below clears it on every exit path (#190).
17552
16683
  deadlineTimer: setTimeout(() => deadline.abort(), timeoutMs)
17553
16684
  };
17554
16685
  try {
17555
- this.gateCooldown(s);
17556
- this.gateBreaker(s);
16686
+ this.gate(s);
17557
16687
  this.logger.debug?.(`[autotask] ${method} ${opts.path}`, correlationId);
17558
16688
  try {
17559
16689
  for (; ; ) {
17560
16690
  const sent = await this.sendOnce(s);
17561
16691
  if (sent.retry) continue;
17562
16692
  const { res, status, text } = sent;
16693
+ s.maintenancePage = isMaintenancePage(status, res.headers.get("Content-Type"), text);
16694
+ if (s.maintenancePage) openMaintenance(this.hostKey, s.maintenancePollMs, this.logger, correlationId);
16695
+ else closeMaintenance(this.hostKey, this.logger, correlationId);
17563
16696
  const step = status >= 200 && status < 300 ? await this.handleSuccess(s, res, status, text) : await this.handleFailureStatus(s, res, status, text);
17564
16697
  if (step.done) {
17565
16698
  this.onSuccess(s, step.status);
@@ -17574,9 +16707,20 @@ var HttpClient = class {
17574
16707
  }
17575
16708
  } finally {
17576
16709
  clearTimeout(s.deadlineTimer);
16710
+ if (s.maintenanceProbe !== void 0) releaseMaintenanceProbe(s.maintenanceProbe.host, s.maintenanceProbe.gate);
17577
16711
  }
17578
16712
  }
17579
16713
  };
16714
+ function isMaintenancePage(status, contentType, text) {
16715
+ if (text.length === 0 || !looksLikeMaintenanceText(text)) return false;
16716
+ if (status >= 200 && status < 300 && (contentType === null || contentType === "" || isJsonMediaType(contentType))) return false;
16717
+ try {
16718
+ JSON.parse(text);
16719
+ return false;
16720
+ } catch {
16721
+ return true;
16722
+ }
16723
+ }
17580
16724
  function assertNoQueryRelationLeaf(opts) {
17581
16725
  const operation = opts.operation ?? opts.path;
17582
16726
  const body = opts.body;
@@ -17712,7 +16856,160 @@ function resolveFieldsPreset(name, resourceKey, explicitIncludeFields) {
17712
16856
  `fieldsPreset: "${name}" is a ${preset.resource} preset \u2014 it cannot be resolved on ${resourceKey} (the preset names its resource; the valid names are: ${FIELD_PRESET_NAMES.join(", ")})`
17713
16857
  );
17714
16858
  }
17715
- return [...preset.fields];
16859
+ return [...preset.fields];
16860
+ }
16861
+
16862
+ // src/resources/base/helpers.ts
16863
+ function describeResponseShape(body) {
16864
+ if (body === null) return "null";
16865
+ if (Array.isArray(body)) return `array(len=${body.length})`;
16866
+ if (typeof body !== "object") return typeof body;
16867
+ const rec = body;
16868
+ const keys = Object.keys(rec).sort();
16869
+ const typeOf = (v) => v === null ? "null" : Array.isArray(v) ? "array" : typeof v;
16870
+ const parts = keys.slice(0, 16).map((k) => `${k}:${typeOf(rec[k])}`);
16871
+ const more = keys.length > 16 ? `, +${keys.length - 16} more` : "";
16872
+ return `{ ${parts.join(", ")}${more} }`;
16873
+ }
16874
+ function defaultMarkerToken(data) {
16875
+ for (const field of ["name", "title"]) {
16876
+ const v = data[field];
16877
+ if (typeof v === "string" && v.trim() !== "") return v.trim();
16878
+ }
16879
+ return null;
16880
+ }
16881
+ var CONTEXT_ABSENT_MARKER = "#context-absent";
16882
+ function contextAbsentKey(path) {
16883
+ return path + "\0context-absent";
16884
+ }
16885
+ function noteCharsTruncationMarker(charsRemoved) {
16886
+ return `\u2026 [+${charsRemoved} chars truncated]`;
16887
+ }
16888
+ function truncateNoteChars(items, cap, fields) {
16889
+ let truncated = 0;
16890
+ const out = items.map((item) => {
16891
+ if (!isRecord2(item)) return item;
16892
+ let changed = false;
16893
+ const copy = { ...item };
16894
+ for (const field of fields) {
16895
+ const v = copy[field];
16896
+ if (typeof v === "string" && v.length > cap) {
16897
+ const end = cap > 0 && (v.charCodeAt(cap - 1) & 64512) === 55296 ? cap - 1 : cap;
16898
+ copy[field] = v.slice(0, end) + noteCharsTruncationMarker(v.length - end);
16899
+ truncated += 1;
16900
+ changed = true;
16901
+ }
16902
+ }
16903
+ return changed ? copy : item;
16904
+ });
16905
+ return [out, truncated];
16906
+ }
16907
+ function blindEmptyReason(stamp) {
16908
+ return {
16909
+ surface: stamp.surface,
16910
+ kind: "blind-surface",
16911
+ note: stamp.note,
16912
+ authority: stamp.authority,
16913
+ remedy: "the note is the remedy \u2014 the authority op answers for a record"
16914
+ };
16915
+ }
16916
+ function attachUpdateTargetMissReason(err, key) {
16917
+ const pinned = EMPTY_REASON_STAMPS[key]?.update;
16918
+ if (pinned === void 0) return;
16919
+ err.details = { ...err.details ?? {}, emptyReason: pinned };
16920
+ }
16921
+ function buildDryRunResult(spec, policy = { redactPersonalData: true }) {
16922
+ if (spec.operation === "") {
16923
+ throw new AutotaskConfigError("dry-run: the operation name is required");
16924
+ }
16925
+ const wouldApply = spec.checks.every((check) => check.ok);
16926
+ const resource = spec.operation.split(".")[0] ?? spec.operation;
16927
+ const diffPart = spec.diff !== void 0 ? {
16928
+ diff: spec.diff.map((entry) => {
16929
+ if (entry.to === void 0) return entry;
16930
+ const to = isRedactedFieldName(entry.field, policy) ? REDACTED : redactResponseBody(entry.to, policy);
16931
+ return { ...entry, to };
16932
+ })
16933
+ } : {};
16934
+ const dataPart = spec.data !== void 0 ? { data: redactResponseBody(spec.data, policy) } : {};
16935
+ return {
16936
+ operation: spec.operation,
16937
+ wouldApply,
16938
+ target: { resource, ids: spec.ids },
16939
+ request: { method: spec.method, path: spec.path },
16940
+ ...diffPart,
16941
+ checks: spec.checks,
16942
+ impact: spec.impact,
16943
+ simulated: true,
16944
+ warnings: spec.warnings ?? [],
16945
+ ...dataPart,
16946
+ ...spec.emptyReason !== void 0 ? { emptyReason: spec.emptyReason } : {}
16947
+ };
16948
+ }
16949
+ function computeFieldDiff(current, data) {
16950
+ const out = [];
16951
+ for (const [field, to] of Object.entries(data)) {
16952
+ if (field === "id" || to === void 0) continue;
16953
+ const from = current[field];
16954
+ if (from !== void 0 && JSON.stringify(from) === JSON.stringify(to)) continue;
16955
+ out.push({ field, from: from === void 0 ? null : from, to });
16956
+ }
16957
+ return out;
16958
+ }
16959
+ function mergePartialBody(current, data) {
16960
+ const merged = { ...current };
16961
+ for (const [key, value] of Object.entries(data)) {
16962
+ if (value === void 0) continue;
16963
+ merged[key] = value;
16964
+ }
16965
+ return merged;
16966
+ }
16967
+ function normalizeUdfInput(value) {
16968
+ if (Array.isArray(value)) {
16969
+ return value.map((entry) => {
16970
+ if (!isRecord2(entry) || typeof entry.name !== "string" || entry.name === "") {
16971
+ throw new AutotaskConfigError("userDefinedFields array entries must be { name, value } objects");
16972
+ }
16973
+ return { name: entry.name, value: entry.value };
16974
+ });
16975
+ }
16976
+ if (isRecord2(value)) {
16977
+ return Object.entries(value).map(([name, entryValue]) => ({ name, value: entryValue }));
16978
+ }
16979
+ throw new AutotaskConfigError("userDefinedFields must be an array of { name, value } entries or a name-to-value map");
16980
+ }
16981
+ function blindStampFor(stamp, filter) {
16982
+ if (stamp === void 0) return void 0;
16983
+ if (stamp.kind !== "unfiltered-blind") return stamp;
16984
+ const conditions = normalizedConditions(filter);
16985
+ return conditions === void 0 || conditions.length === 0 ? stamp : void 0;
16986
+ }
16987
+ function decodeFileData(body) {
16988
+ if (isRecord2(body)) {
16989
+ const data = body.data;
16990
+ if (typeof data === "string") return Buffer.from(data, "base64");
16991
+ if (Array.isArray(data) && data.every((b) => typeof b === "number")) {
16992
+ return Buffer.from(data);
16993
+ }
16994
+ }
16995
+ if (typeof body === "string") return Buffer.from(body, "base64");
16996
+ throw new AutotaskError(
16997
+ "Expected the file envelope FileQueryResultModel { data } (or a base64 string); got a different shape",
16998
+ { code: "INVALID_RESPONSE", category: "server" }
16999
+ );
17000
+ }
17001
+ var DEPLURAL_EXCEPTIONS = {
17002
+ tag_aliase: "tag_alias"
17003
+ };
17004
+ function entityNameFromPath(resourcePath) {
17005
+ const segment = resourcePath.slice(resourcePath.lastIndexOf("/") + 1);
17006
+ const snake = segment.replace(/([A-Z])/g, (_m, c, i) => (i > 0 ? `_` : "") + c.toLowerCase()).replace(/_{2,}/g, "_");
17007
+ if (snake.endsWith("ies")) return `${snake.slice(0, -3)}y`;
17008
+ if (snake.endsWith("s")) {
17009
+ const stripped = snake.slice(0, -1);
17010
+ return DEPLURAL_EXCEPTIONS[stripped] ?? stripped;
17011
+ }
17012
+ return snake;
17716
17013
  }
17717
17014
 
17718
17015
  // src/operations/expandResourceNames.ts
@@ -17775,54 +17072,35 @@ async function expandResourceNames(client, ids2, opts = {}) {
17775
17072
  }
17776
17073
  }
17777
17074
  const holder = client.resources;
17778
- const cache = client.http.resourceNameCache;
17075
+ const cache = client.http.readCache;
17779
17076
  const fresh = opts.fresh === true;
17780
17077
  const byId = /* @__PURE__ */ new Map();
17781
17078
  for (const id of unique) {
17782
17079
  const k = String(id);
17783
- if (cache !== void 0 && !fresh) {
17784
- const shared = cache.inflight(id);
17785
- if (shared !== void 0) {
17786
- let joined;
17787
- try {
17788
- joined = await shared;
17789
- } catch (err) {
17790
- if (!isAutotaskError(err) || err.code !== "ABORTED") throw err;
17791
- }
17792
- if (joined !== void 0) {
17793
- byId.set(k, joined);
17794
- continue;
17795
- }
17080
+ const absentKey = contextAbsentKey(`/V1.0/Resources/${k}`);
17081
+ if (cache !== void 0 && !fresh && cache.get(absentKey) !== void 0) {
17082
+ byId.set(k, { name: null, blind: true });
17083
+ continue;
17084
+ }
17085
+ const epoch = cache?.epoch ?? 0;
17086
+ try {
17087
+ const record = await holder.get(id, { fresh });
17088
+ cache?.delete(absentKey);
17089
+ byId.set(k, { name: composeName(record), blind: false });
17090
+ } catch (err) {
17091
+ if (err instanceof NotFoundError) {
17092
+ cache?.set(absentKey, CONTEXT_ABSENT_MARKER, epoch);
17093
+ byId.set(k, { name: null, blind: true });
17094
+ continue;
17796
17095
  }
17797
- const hit = cache.get(id);
17798
- if (hit !== void 0) {
17799
- byId.set(k, { name: hit.name, blind: hit.blind });
17096
+ if (isAutotaskError(err) && err.code !== "ABORTED") {
17097
+ const e = { code: err.code, message: err.message };
17098
+ if (err.httpStatus !== void 0) e.httpStatus = err.httpStatus;
17099
+ byId.set(k, { name: null, blind: false, error: e });
17800
17100
  continue;
17801
17101
  }
17102
+ throw err;
17802
17103
  }
17803
- const epoch = cache?.epoch ?? 0;
17804
- const work = (async () => {
17805
- try {
17806
- const record = await holder.get(id, { fresh });
17807
- const name = composeName(record);
17808
- if (cache !== void 0 && name !== null) cache.set(id, { name, blind: false }, epoch);
17809
- return { name, blind: false };
17810
- } catch (err) {
17811
- if (err instanceof NotFoundError) {
17812
- const entry = { name: null, blind: true };
17813
- if (cache !== void 0) cache.set(id, entry, epoch);
17814
- return { name: null, blind: true };
17815
- }
17816
- if (isAutotaskError(err) && err.code !== "ABORTED") {
17817
- const e = { code: err.code, message: err.message };
17818
- if (err.httpStatus !== void 0) e.httpStatus = err.httpStatus;
17819
- return { name: null, blind: false, error: e };
17820
- }
17821
- throw err;
17822
- }
17823
- })();
17824
- const settled = cache !== void 0 ? await cache.track(id, work) : await work;
17825
- byId.set(k, settled);
17826
17104
  }
17827
17105
  const results = [];
17828
17106
  for (const id of canonical) {
@@ -18167,7 +17445,7 @@ async function sweepResource(ctx, resource, tally) {
18167
17445
  error: null
18168
17446
  };
18169
17447
  const fetches = kindFetches(holder, resource);
18170
- if (fresh) cache?.invalidate(resource);
17448
+ if (fresh) cache?.invalidate(`${resource}:`);
18171
17449
  const projectList = (kind, list) => {
18172
17450
  const projected = list.map((f) => projectFieldRow(f, labels, kind === "udf"));
18173
17451
  if (kind === "fields") applyFieldsFilter(projected, fieldsFilter, row);
@@ -18177,10 +17455,10 @@ async function sweepResource(ctx, resource, tally) {
18177
17455
  let allCached = true;
18178
17456
  const ages = [];
18179
17457
  for (const kind of include) {
18180
- const peek = cache !== void 0 && !fresh ? cache.peek(resource, kind) : { hit: false, age: null };
17458
+ const peek = cache !== void 0 && !fresh ? cache.peek(fieldKey(resource, kind)) : { hit: false, age: null };
18181
17459
  if (peek.hit !== true) allCached = false;
18182
17460
  if (peek.hit === true && cache !== void 0) {
18183
- const value2 = cache.get(resource, kind);
17461
+ const value2 = cache.get(fieldKey(resource, kind));
18184
17462
  if (kind === "info") row.info = value2 ?? null;
18185
17463
  else projectList(kind, Array.isArray(value2) ? value2 : []);
18186
17464
  if (peek.age !== null) ages.push(peek.age);
@@ -18471,159 +17749,6 @@ var BOUNDED_QUERY_MAX_LIMIT = 2500;
18471
17749
  var LATEST_MAX_COUNT_PROBES = 64;
18472
17750
  var MARKER_RECOVERY_LIMIT = 5;
18473
17751
 
18474
- // src/resources/base/helpers.ts
18475
- function describeResponseShape(body) {
18476
- if (body === null) return "null";
18477
- if (Array.isArray(body)) return `array(len=${body.length})`;
18478
- if (typeof body !== "object") return typeof body;
18479
- const rec = body;
18480
- const keys = Object.keys(rec).sort();
18481
- const typeOf = (v) => v === null ? "null" : Array.isArray(v) ? "array" : typeof v;
18482
- const parts = keys.slice(0, 16).map((k) => `${k}:${typeOf(rec[k])}`);
18483
- const more = keys.length > 16 ? `, +${keys.length - 16} more` : "";
18484
- return `{ ${parts.join(", ")}${more} }`;
18485
- }
18486
- function defaultMarkerToken(data) {
18487
- for (const field of ["name", "title"]) {
18488
- const v = data[field];
18489
- if (typeof v === "string" && v.trim() !== "") return v.trim();
18490
- }
18491
- return null;
18492
- }
18493
- var CONTEXT_ABSENT_MARKER = "#context-absent";
18494
- function contextAbsentKey(path) {
18495
- return path + "\0context-absent";
18496
- }
18497
- function noteCharsTruncationMarker(charsRemoved) {
18498
- return `\u2026 [+${charsRemoved} chars truncated]`;
18499
- }
18500
- function truncateNoteChars(items, cap, fields) {
18501
- let truncated = 0;
18502
- const out = items.map((item) => {
18503
- if (!isRecord2(item)) return item;
18504
- let changed = false;
18505
- const copy = { ...item };
18506
- for (const field of fields) {
18507
- const v = copy[field];
18508
- if (typeof v === "string" && v.length > cap) {
18509
- const end = cap > 0 && (v.charCodeAt(cap - 1) & 64512) === 55296 ? cap - 1 : cap;
18510
- copy[field] = v.slice(0, end) + noteCharsTruncationMarker(v.length - end);
18511
- truncated += 1;
18512
- changed = true;
18513
- }
18514
- }
18515
- return changed ? copy : item;
18516
- });
18517
- return [out, truncated];
18518
- }
18519
- function blindEmptyReason(stamp) {
18520
- return {
18521
- surface: stamp.surface,
18522
- kind: "blind-surface",
18523
- note: stamp.note,
18524
- authority: stamp.authority,
18525
- remedy: "the note is the remedy \u2014 the authority op answers for a record"
18526
- };
18527
- }
18528
- function attachUpdateTargetMissReason(err, key) {
18529
- const pinned = EMPTY_REASON_STAMPS[key]?.update;
18530
- if (pinned === void 0) return;
18531
- err.details = { ...err.details ?? {}, emptyReason: pinned };
18532
- }
18533
- function buildDryRunResult(spec, policy = { redactPersonalData: true }) {
18534
- if (spec.operation === "") {
18535
- throw new AutotaskConfigError("dry-run: the operation name is required");
18536
- }
18537
- const wouldApply = spec.checks.every((check) => check.ok);
18538
- const resource = spec.operation.split(".")[0] ?? spec.operation;
18539
- const diffPart = spec.diff !== void 0 ? {
18540
- diff: spec.diff.map((entry) => {
18541
- if (entry.to === void 0) return entry;
18542
- const to = isRedactedFieldName(entry.field, policy) ? REDACTED : redactResponseBody(entry.to, policy);
18543
- return { ...entry, to };
18544
- })
18545
- } : {};
18546
- const dataPart = spec.data !== void 0 ? { data: redactResponseBody(spec.data, policy) } : {};
18547
- return {
18548
- operation: spec.operation,
18549
- wouldApply,
18550
- target: { resource, ids: spec.ids },
18551
- request: { method: spec.method, path: spec.path },
18552
- ...diffPart,
18553
- checks: spec.checks,
18554
- impact: spec.impact,
18555
- simulated: true,
18556
- warnings: spec.warnings ?? [],
18557
- ...dataPart,
18558
- ...spec.emptyReason !== void 0 ? { emptyReason: spec.emptyReason } : {}
18559
- };
18560
- }
18561
- function computeFieldDiff(current, data) {
18562
- const out = [];
18563
- for (const [field, to] of Object.entries(data)) {
18564
- if (field === "id" || to === void 0) continue;
18565
- const from = current[field];
18566
- if (from !== void 0 && JSON.stringify(from) === JSON.stringify(to)) continue;
18567
- out.push({ field, from: from === void 0 ? null : from, to });
18568
- }
18569
- return out;
18570
- }
18571
- function mergePartialBody(current, data) {
18572
- const merged = { ...current };
18573
- for (const [key, value] of Object.entries(data)) {
18574
- if (value === void 0) continue;
18575
- merged[key] = value;
18576
- }
18577
- return merged;
18578
- }
18579
- function normalizeUdfInput(value) {
18580
- if (Array.isArray(value)) {
18581
- return value.map((entry) => {
18582
- if (!isRecord2(entry) || typeof entry.name !== "string" || entry.name === "") {
18583
- throw new AutotaskConfigError("userDefinedFields array entries must be { name, value } objects");
18584
- }
18585
- return { name: entry.name, value: entry.value };
18586
- });
18587
- }
18588
- if (isRecord2(value)) {
18589
- return Object.entries(value).map(([name, entryValue]) => ({ name, value: entryValue }));
18590
- }
18591
- throw new AutotaskConfigError("userDefinedFields must be an array of { name, value } entries or a name-to-value map");
18592
- }
18593
- function blindStampFor(stamp, filter) {
18594
- if (stamp === void 0) return void 0;
18595
- if (stamp.kind !== "unfiltered-blind") return stamp;
18596
- const conditions = normalizedConditions(filter);
18597
- return conditions === void 0 || conditions.length === 0 ? stamp : void 0;
18598
- }
18599
- function decodeFileData(body) {
18600
- if (isRecord2(body)) {
18601
- const data = body.data;
18602
- if (typeof data === "string") return Buffer.from(data, "base64");
18603
- if (Array.isArray(data) && data.every((b) => typeof b === "number")) {
18604
- return Buffer.from(data);
18605
- }
18606
- }
18607
- if (typeof body === "string") return Buffer.from(body, "base64");
18608
- throw new AutotaskError(
18609
- "Expected the file envelope FileQueryResultModel { data } (or a base64 string); got a different shape",
18610
- { code: "INVALID_RESPONSE", category: "server" }
18611
- );
18612
- }
18613
- var DEPLURAL_EXCEPTIONS = {
18614
- tag_aliase: "tag_alias"
18615
- };
18616
- function entityNameFromPath(resourcePath) {
18617
- const segment = resourcePath.slice(resourcePath.lastIndexOf("/") + 1);
18618
- const snake = segment.replace(/([A-Z])/g, (_m, c, i) => (i > 0 ? `_` : "") + c.toLowerCase()).replace(/_{2,}/g, "_");
18619
- if (snake.endsWith("ies")) return `${snake.slice(0, -3)}y`;
18620
- if (snake.endsWith("s")) {
18621
- const stripped = snake.slice(0, -1);
18622
- return DEPLURAL_EXCEPTIONS[stripped] ?? stripped;
18623
- }
18624
- return snake;
18625
- }
18626
-
18627
17752
  // src/resources/special/_shared/bounded-part.ts
18628
17753
  async function boundedPart(http, path, conditions, limit, operation, includeFields) {
18629
17754
  const body = { MaxRecords: limit, filter: conditions };
@@ -19039,59 +18164,18 @@ var QueryBase = class {
19039
18164
  const bigB = typeof b === "number" ? BigInt(String(b)) : BigInt(b);
19040
18165
  return bigA < bigB ? -1 : bigA > bigB ? 1 : 0;
19041
18166
  }
19042
- /** Issue #127: the `latest` walk's count probes through the per-client
19043
- * short-TTL count cache (`LatestCountCache` — fixed 30 s TTL, the
19044
- * memory guard; cleared on every real write through this client, the
19045
- * write-then-read re-fetch rule). Only a SUCCESSFUL plain-number vendor
19046
- * count answer is stored: the blind-surface / pinned-empty sentinels are
19047
- * RECORDS and pass through un-stored (the plan-pinned stamps stay fresh
19048
- * and re-derive on every call), and an error rejects before any store.
19049
- * The key is (resource plan key, canonical filter serialisation — the
19050
- * normalised conditions' JSON): the initial `count(F)` probe and every
19051
- * `id gt T` threshold probe are separate entries, and a re-asked
19052
- * "top N" within the TTL makes ZERO extra count calls for every CACHED
19053
- * probe (the bracket/search sequence is deterministic given the counts);
19054
- * a probe that answered 0 is never cached, so it re-wires (issue #157).
19055
- * Issue #157: two corrections to the snapshot trade. (1) A total of 0 is
19056
- * NEVER stored — a 0 is rare and cheap to re-probe, and a cached 0 fed
19057
- * the false-empty branch (a repeat after an out-of-band insert returned
19058
- * no rows without walking). (2) `fresh: true` DELETES the entry before
19059
- * the wire read and re-stores the fresh answer — the ONE re-probe the
19060
- * stale-LOW recovery in `latestWalk` is allowed. Counts are snapshots,
19061
- * not contracts: the truncation guard covers the growth-of-total
19062
- * direction; a stale-LOW total within the TTL is resolved by that one
19063
- * fresh re-probe (never by the guard alone). The plain `count` op and
19064
- * `operations.aggregate` call `countGlobal` directly and promise fresh
19065
- * totals — this wrapper is used ONLY on the latest-walk probe path.
19066
- * @internal
19067
- */
19068
- async latestProbeCount(filter, opts = {}) {
19069
- const cache = this.http.latestCountCache;
19070
- const key = LatestCountCache.key(this.config.key, normalizedConditions(filter));
19071
- if (opts.fresh === true) {
19072
- cache.delete(key);
19073
- } else {
19074
- const hit = cache.get(key);
19075
- if (hit !== void 0) return { value: hit, cached: true };
19076
- }
19077
- const epoch = cache.epoch;
19078
- const res = await this.countGlobal({ filter });
19079
- const value = res;
19080
- if (typeof value === "number" && value !== 0) cache.set(key, value, epoch);
19081
- return { value, cached: false };
19082
- }
19083
18167
  /** Issue #59: one `latest` threshold count probe — a ROWLESS
19084
18168
  * `count(F ∧ id gt T)` call (the vendor caps — ≤500 OR-conditions,
19085
18169
  * 8000 chars serialised — leave a single `gt` condition room on any
19086
- * filter). Issue #127: it rides the per-client short-TTL count cache — the same (resource, conditions) probe within the 30 s window is reused (zero vendor calls); a sentinel answer is never cached. The `BlindCountResult` sentinel (a record, not a number —
18170
+ * filter). Counts are never cached. The `BlindCountResult` sentinel (a record, not a number —
19087
18171
  * the declared `number` return is the documented under-type) unwraps to
19088
18172
  * its `count` value (always 0): at or above the max matching id the
19089
18173
  * count is 0, which is exactly the bracket-termination signal.
19090
18174
  * @internal */
19091
18175
  async countAboveId(baseConds, t) {
19092
18176
  const value = t <= BigInt(Number.MAX_SAFE_INTEGER) ? Number(t) : t.toString();
19093
- const probed = await this.latestProbeCount([...baseConds, { op: "gt", field: "id", value }]);
19094
- return typeof probed.value === "object" && probed.value !== null && "count" in probed.value ? probed.value.count : probed.value;
18177
+ const probed = await this.countGlobal({ filter: [...baseConds, { op: "gt", field: "id", value }] });
18178
+ return typeof probed === "object" && probed !== null && "count" in probed ? probed.count : probed;
19095
18179
  }
19096
18180
  /**
19097
18181
  * Issue #59: the `latest: N` mechanism — the N highest-`id` rows,
@@ -19109,10 +18193,7 @@ var QueryBase = class {
19109
18193
  * 1 + ceil(C/500) <= 6, independent of table size. A truncated walk
19110
18194
  * (the vendor's rows disagree with its own count) is
19111
18195
  * LATEST_WINDOW_INCOMPLETE — the top-N of a truncated set is
19112
- * unprovable — EXCEPT issue #157: when `C` came from the CACHE, the
19113
- * total is re-probed ONCE fresh (the stale-LOW recovery: a larger
19114
- * fresh total continues the walk against it; the refusal stands only
19115
- * when the fresh probe confirms the cached value). Sort
18196
+ * unprovable. Sort
19116
18197
  * id-descending; return the top N (a set of C < N returns itself).
19117
18198
  * - `C > 2500` → THRESHOLD mode: find the smallest id threshold `T`
19118
18199
  * with `count(F ∧ id gt T) <= N` by exponential bracketing
@@ -19140,30 +18221,15 @@ var QueryBase = class {
19140
18221
  * answer.
19141
18222
  * `includeFields` always carries `id` (the P1 id-append,
19142
18223
  * `buildQueryRequest`), which `latest` sorts on. Pure read; no mutation
19143
- * paths involved. Issue #127: every count probe of this walk (the
19144
- * initial `count(F)` + the `id gt T` threshold probes) rides the
19145
- * per-client short-TTL count cache (30 s; a real write through this
19146
- * client clears it) — a re-asked "top N" within the window reuses every
19147
- * CACHED probe (zero extra vendor count calls); sentinel answers are
19148
- * never cached (the plan-pinned stamps stay fresh), and a 0 total is
19149
- * never cached either (issue #157: a 0 is cheap to re-probe and a cached
19150
- * 0 would shadow an out-of-band insert), so a 0-answering probe re-wires.
19151
- * The stale-LOW direction is closed by the ONE fresh re-probe above. The
19152
- * stale-HIGH direction is the documented snapshot trade, NOT "safe by
19153
- * construction": the threshold probes are cache-served like every other
19154
- * probe (no fresh re-probe exists on that path), so a cached threshold
19155
- * count higher than reality can under-report the ROW COUNT within the
19156
- * TTL — the returned top-N stays correct, and full-set mode ends when the
19157
- * cursor exhausts. The plain `count` op and
19158
- * `operations.aggregate` bypass the cache by construction and promise
19159
- * fresh totals.
18224
+ * paths involved; every count probe goes to the wire (counts are never
18225
+ * cached).
19160
18226
  * @internal
19161
18227
  */
19162
18228
  async latestWalk(params, limit, latest) {
19163
18229
  const baseConds = normalizedConditions(params.filter) ?? [];
19164
- const probe = await this.latestProbeCount(params.filter);
19165
- if (typeof probe.value === "object" && probe.value !== null) {
19166
- const rec = probe.value;
18230
+ const total = await this.countGlobal({ filter: params.filter });
18231
+ if (typeof total === "object" && total !== null) {
18232
+ const rec = total;
19167
18233
  if (rec.blindSurface !== void 0) {
19168
18234
  return this.latestBlindWalk(params, limit, latest);
19169
18235
  }
@@ -19171,60 +18237,46 @@ var QueryBase = class {
19171
18237
  this.stampEmptyQueryResult(result, params);
19172
18238
  return result;
19173
18239
  }
19174
- let total = probe.value;
19175
- let cacheSourced = probe.cached;
19176
- let reProbed = false;
19177
- for (; ; ) {
19178
- if (total === 0) {
19179
- const result = { items: [], fetched: 0, hasMore: false, pagesWalked: 0 };
19180
- this.stampEmptyQueryResult(result, params);
19181
- return result;
19182
- }
19183
- if (total <= BOUNDED_QUERY_MAX_LIMIT) {
19184
- const { items: items2, pages: pages2, guard: guard2, sliced: sliced2, cursor: cursor2 } = await this.walkBounded(params, total);
19185
- if (this.walkTruncated(total, { itemsLength: items2.length, guard: guard2, sliced: sliced2, cursor: cursor2 })) {
19186
- if (cacheSourced && !reProbed) {
19187
- reProbed = true;
19188
- const fresh = await this.latestProbeCount(params.filter, { fresh: true });
19189
- if (typeof fresh.value === "number" && fresh.value > total) {
19190
- total = fresh.value;
19191
- cacheSourced = false;
19192
- continue;
19193
- }
19194
- }
19195
- throw this.latestWindowIncompleteError(total);
19196
- }
19197
- return this.finishLatest(items2, latest, pages2);
19198
- }
19199
- let probes = reProbed ? 2 : 1;
19200
- const spend = () => {
19201
- probes += 1;
19202
- if (probes > LATEST_MAX_COUNT_PROBES) throw this.latestThresholdUnresolvedError();
19203
- };
19204
- let lo = 0n;
19205
- let hi = 0n;
19206
- for (let t = 1n; ; t = t << 1n) {
19207
- spend();
19208
- if (await this.countAboveId(baseConds, t) <= latest) {
19209
- hi = t;
19210
- break;
19211
- }
19212
- lo = t;
19213
- }
19214
- while (hi - lo > 1n) {
19215
- const mid = lo + hi >> 1n;
19216
- spend();
19217
- if (await this.countAboveId(baseConds, mid) <= latest) hi = mid;
19218
- else lo = mid;
18240
+ if (total === 0) {
18241
+ const result = { items: [], fetched: 0, hasMore: false, pagesWalked: 0 };
18242
+ this.stampEmptyQueryResult(result, params);
18243
+ return result;
18244
+ }
18245
+ if (total <= BOUNDED_QUERY_MAX_LIMIT) {
18246
+ const { items: items2, pages: pages2, guard: guard2, sliced: sliced2, cursor: cursor2 } = await this.walkBounded(params, total);
18247
+ if (this.walkTruncated(total, { itemsLength: items2.length, guard: guard2, sliced: sliced2, cursor: cursor2 })) {
18248
+ throw this.latestWindowIncompleteError(total);
19219
18249
  }
19220
- const windowValue = hi <= BigInt(Number.MAX_SAFE_INTEGER) ? Number(hi) : hi.toString();
19221
- const window = [...baseConds, { op: "gte", field: "id", value: windowValue }];
19222
- const { items, pages, guard, sliced, cursor } = await this.walkBounded({ ...params, filter: window }, latest + 1);
19223
- if (this.walkTruncated(latest + 1, { itemsLength: items.length, guard, sliced, cursor })) {
19224
- throw this.latestWindowIncompleteError(latest + 1);
18250
+ return this.finishLatest(items2, latest, pages2);
18251
+ }
18252
+ let probes = 1;
18253
+ const spend = () => {
18254
+ probes += 1;
18255
+ if (probes > LATEST_MAX_COUNT_PROBES) throw this.latestThresholdUnresolvedError();
18256
+ };
18257
+ let lo = 0n;
18258
+ let hi = 0n;
18259
+ for (let t = 1n; ; t = t << 1n) {
18260
+ spend();
18261
+ if (await this.countAboveId(baseConds, t) <= latest) {
18262
+ hi = t;
18263
+ break;
19225
18264
  }
19226
- return this.finishLatest(items, latest, pages);
18265
+ lo = t;
19227
18266
  }
18267
+ while (hi - lo > 1n) {
18268
+ const mid = lo + hi >> 1n;
18269
+ spend();
18270
+ if (await this.countAboveId(baseConds, mid) <= latest) hi = mid;
18271
+ else lo = mid;
18272
+ }
18273
+ const windowValue = hi <= BigInt(Number.MAX_SAFE_INTEGER) ? Number(hi) : hi.toString();
18274
+ const window = [...baseConds, { op: "gte", field: "id", value: windowValue }];
18275
+ const { items, pages, guard, sliced, cursor } = await this.walkBounded({ ...params, filter: window }, latest + 1);
18276
+ if (this.walkTruncated(latest + 1, { itemsLength: items.length, guard, sliced, cursor })) {
18277
+ throw this.latestWindowIncompleteError(latest + 1);
18278
+ }
18279
+ return this.finishLatest(items, latest, pages);
19228
18280
  }
19229
18281
  /** The shared `latest` completion: the (provably complete or
19230
18282
  * stamp-scoped) set sorted id-descending, top N taken. `hasMore: false`
@@ -19335,11 +18387,9 @@ var MetaBase = class extends QueryBase {
19335
18387
  * other callers): mutation-path reads (stale-object guard, dry-run diff)
19336
18388
  * and the composite ROOT read of a hot resource (issue #36 — the
19337
18389
  * ticket-composite root) must see the live record, never a snapshot.
19338
- * `resource` (issue #32) is the plan key of the entity this path
19339
- * points to: the stored entry's TTL is the per-resource override for
19340
- * that key when `cache.perResourceTtlMs` names it, else `ttlMs`.
18390
+ * The entry's TTL follows the path (`readTtlFor`: reference tables 1 h).
19341
18391
  * @internal */
19342
- async cachedGet(path, operation, fresh = false, resource) {
18392
+ async cachedGet(path, operation, fresh = false) {
19343
18393
  const cache = this.http.readCache;
19344
18394
  if (cache !== void 0 && !fresh) {
19345
18395
  const hit = cache.get(path);
@@ -19347,7 +18397,7 @@ var MetaBase = class extends QueryBase {
19347
18397
  }
19348
18398
  const epoch = cache?.epoch;
19349
18399
  const res = await this.http.request({ method: "GET", path, operation });
19350
- cache?.set(path, res, resource, epoch);
18400
+ cache?.set(path, res, epoch);
19351
18401
  return res;
19352
18402
  }
19353
18403
  /**
@@ -19374,29 +18424,29 @@ var MetaBase = class extends QueryBase {
19374
18424
  const res = await this.http.request({ method: "GET", path, operation });
19375
18425
  return unwrap(res);
19376
18426
  }
19377
- const key = this.config.key;
18427
+ const key = fieldKey(this.config.key, kind);
19378
18428
  if (!fresh) {
19379
- const shared = cache.inflight(key, kind);
18429
+ const shared = cache.inflight(key);
19380
18430
  if (shared !== void 0) return shared;
19381
- const hit = cache.get(key, kind);
18431
+ const hit = cache.get(key);
19382
18432
  if (hit !== void 0) return hit;
19383
18433
  }
19384
18434
  const work = this.http.request({ method: "GET", path, operation }).then((body) => {
19385
18435
  const value = unwrap(body);
19386
- cache.set(key, kind, value);
18436
+ if (!isEmpty(value)) cache.set(key, value);
19387
18437
  return value;
19388
18438
  });
19389
18439
  work.catch((err) => {
19390
18440
  if (err instanceof AutotaskError && (err.code === "INVALID_RESPONSE" || err.details?.deterministic === true)) {
19391
- cache.invalidate(key);
18441
+ cache.invalidate(`${this.config.key}:`);
19392
18442
  }
19393
18443
  });
19394
- return cache.track(key, kind, work);
18444
+ return cache.track(key, work);
19395
18445
  }
19396
18446
  /** `GET /V1.0/<E>/{id}` → `{ item }` unwrapped (`item: null` → NotFoundError). */
19397
18447
  async getGlobal(id, fresh = false) {
19398
18448
  const numeric = parseIdentifier(id, "id");
19399
- const res = await this.cachedGet(`${this.resourcePath}/${numeric}`, `${this.config.key}.get`, fresh, this.config.key);
18449
+ const res = await this.cachedGet(`${this.resourcePath}/${numeric}`, `${this.config.key}.get`, fresh);
19400
18450
  return unwrapItem(res, numeric, `${this.config.key}.get`, this.entityName);
19401
18451
  }
19402
18452
  /**
@@ -19443,7 +18493,7 @@ var MetaBase = class extends QueryBase {
19443
18493
  /** Parent-scoped `GET .../{parentId}/<Child>/{id}` → `{ item }` unwrapped. */
19444
18494
  async getScopedRaw(parentId, id, fresh = false) {
19445
18495
  const numeric = parseIdentifier(id, "id");
19446
- const res = await this.cachedGet(this.scopedItemPath(parentId, id), `${this.config.key}.get`, fresh, this.config.key);
18496
+ const res = await this.cachedGet(this.scopedItemPath(parentId, id), `${this.config.key}.get`, fresh);
19447
18497
  return unwrapItem(res, numeric, `${this.config.key}.get`, this.entityName);
19448
18498
  }
19449
18499
  /**
@@ -19453,7 +18503,7 @@ var MetaBase = class extends QueryBase {
19453
18503
  */
19454
18504
  async getScopedModel(parentId, id, fresh = false) {
19455
18505
  const numeric = parseIdentifier(id, "id");
19456
- const res = await this.cachedGet(this.scopedItemPath(parentId, id), `${this.config.key}.get`, fresh, this.config.key);
18506
+ const res = await this.cachedGet(this.scopedItemPath(parentId, id), `${this.config.key}.get`, fresh);
19457
18507
  return this.unwrapModelLike(res, numeric, this.entityName);
19458
18508
  }
19459
18509
  /** @internal */
@@ -19492,7 +18542,7 @@ var MetaBase = class extends QueryBase {
19492
18542
  // ------------------------------------------------------------------
19493
18543
  /** `GET /V1.0/<E>/entityInformation` → `{ info }` unwrapped.
19494
18544
  * Goes through the field cache when it is present (issue #80:
19495
- * default-on; `fieldCache: false` = the bit-for-bit uncached wire
18545
+ * default-on; `cache: false` = the bit-for-bit uncached wire
19496
18546
  * path). A fresh
19497
18547
  * (bypass + refresh) metadata read is the caller's act: drop the
19498
18548
  * entity's entries via the fieldCache's `invalidate` first — the trio
@@ -19516,7 +18566,7 @@ var MetaBase = class extends QueryBase {
19516
18566
  }
19517
18567
  /** `GET /V1.0/<E>/entityInformation/fields` → `{ fields }` unwrapped.
19518
18568
  * Goes through the field cache when it is present (issue #80:
19519
- * default-on; `fieldCache: false` = the bit-for-bit uncached wire
18569
+ * default-on; `cache: false` = the bit-for-bit uncached wire
19520
18570
  * path). A fresh
19521
18571
  * (bypass + refresh) metadata read is the caller's act: drop the
19522
18572
  * entity's entries via the fieldCache's `invalidate` first — the trio
@@ -19531,7 +18581,7 @@ var MetaBase = class extends QueryBase {
19531
18581
  }
19532
18582
  /** `GET /V1.0/<E>/entityInformation/userDefinedFields` → `{ fields }` unwrapped.
19533
18583
  * Goes through the field cache when it is present (issue #80:
19534
- * default-on; `fieldCache: false` = the bit-for-bit uncached wire
18584
+ * default-on; `cache: false` = the bit-for-bit uncached wire
19535
18585
  * path). A fresh
19536
18586
  * (bypass + refresh) metadata read is the caller's act: drop the
19537
18587
  * entity's entries via the fieldCache's `invalidate` first — the trio
@@ -19598,8 +18648,7 @@ var MetaBase = class extends QueryBase {
19598
18648
  * record, never a snapshot. */
19599
18649
  async fetchRecordRaw(entityPath, id, fresh = false) {
19600
18650
  const numeric = parseIdentifier(id, "id");
19601
- const resource = RESOURCE_KEY_BY_PATH[entityPath];
19602
- const res = await this.cachedGet(`${entityPath}/${numeric}`, `${this.config.key}.fetchRecord`, fresh, resource);
18651
+ const res = await this.cachedGet(`${entityPath}/${numeric}`, `${this.config.key}.fetchRecord`, fresh);
19603
18652
  if (this.config.attachmentGet) {
19604
18653
  return this.unwrapModelLike(res, numeric, entityNameFromPath(entityPath));
19605
18654
  }
@@ -19613,16 +18662,16 @@ var MetaBase = class extends QueryBase {
19613
18662
  *
19614
18663
  * Issue #36 (negative caching, the pinned hazard): the vendor's true
19615
18664
  * not-found (the HTTP 404 or the 200 `item: null` signal — both surface
19616
- * as `NotFoundError`) is stored as an ABSENT marker in the SAME ReadCache
18665
+ * as `NotFoundError`) is stored as an ABSENT marker in the SAME read cache
19617
18666
  * under a namespaced key the positive get path never constructs, so a
19618
18667
  * repeat composite call serves 'absent' with zero wire for that part.
19619
- * The marker expires on the READ entity's TTL (the #32 per-resource
19620
- * table / `perResourceTtlMs` override, via `set`'s resource key) and is
19621
- * cleared by any real write through the client (the ReadCache clear).
18668
+ * The marker expires on the READ entity's TTL (the key carries the read
18669
+ * path, so `readTtlFor` applies) and is
18670
+ * cleared by any real write through the client (the read cache clear).
19622
18671
  * A transient fault (5xx, shape drift, network) is NEVER stored as an
19623
18672
  * ABSENT marker — it propagates and the next call re-wires (no
19624
18673
  * poisoning; a malformed 200 body may still land under the POSITIVE
19625
- * key — pre-existing ReadCache behaviour, out of this mechanism's
18674
+ * key — pre-existing read cache behaviour, out of this mechanism's
19626
18675
  * scope). The marker is consulted BEFORE the positive lookup, but a
19627
18676
  * POSITIVE entry that exists alongside a live marker means a newer
19628
18677
  * positive outcome (this client read/created the record after the
@@ -19650,7 +18699,7 @@ var MetaBase = class extends QueryBase {
19650
18699
  return await this.fetchRecordRaw(entityPath, referenceId);
19651
18700
  } catch (err) {
19652
18701
  if (err instanceof NotFoundError) {
19653
- cache?.set(absentKey, CONTEXT_ABSENT_MARKER, RESOURCE_KEY_BY_PATH[entityPath], epoch);
18702
+ cache?.set(absentKey, CONTEXT_ABSENT_MARKER, epoch);
19654
18703
  return null;
19655
18704
  }
19656
18705
  throw err;
@@ -19895,6 +18944,11 @@ var MetaBase = class extends QueryBase {
19895
18944
  });
19896
18945
  }
19897
18946
  };
18947
+ function isEmpty(value) {
18948
+ if (value === null || value === void 0) return true;
18949
+ if (Array.isArray(value)) return value.length === 0;
18950
+ return typeof value === "object" && Object.keys(value).length === 0;
18951
+ }
19898
18952
 
19899
18953
  // src/resources/base/mutations.ts
19900
18954
  var MutationBase = class extends MetaBase {
@@ -20714,15 +19768,14 @@ async function resolveCompositeNames(http, plan, opts = {}) {
20714
19768
  throw new AutotaskConfigError("composite names: the transport is not wired to an AutotaskClient (the composite must run through the client)");
20715
19769
  }
20716
19770
  const readCache = http.readCache;
20717
- const nameCache = http.resourceNameCache;
20718
19771
  const section = { truncated: false, rows: {}, reasons: {} };
20719
19772
  let remaining = budget;
20720
19773
  let contractLobPointer;
20721
19774
  let contractLobUnread;
20722
19775
  const coldResource = [];
20723
19776
  for (const id of plan.resourceIds) {
20724
- if (nameCache !== void 0 && nameCache.get(id) !== void 0) continue;
20725
- if (readCache !== void 0 && readCache.get(`/V1.0/Resources/${id}`) !== void 0) continue;
19777
+ const path = `/V1.0/Resources/${id}`;
19778
+ if (readCache !== void 0 && (readCache.peek(path).hit || readCache.peek(contextAbsentKey(path)).hit)) continue;
20726
19779
  coldResource.push(id);
20727
19780
  }
20728
19781
  const withinBudget = coldResource.slice(0, remaining);
@@ -22022,11 +21075,11 @@ function picklistOf(fields) {
22022
21075
  }
22023
21076
  async function readFields(http, fresh) {
22024
21077
  const cache = http.fieldCache;
22025
- const key = "tickets";
21078
+ const key = fieldKey("tickets", "fields");
22026
21079
  if (!fresh && cache !== void 0) {
22027
- const shared = cache.inflight(key, "fields");
21080
+ const shared = cache.inflight(key);
22028
21081
  if (shared !== void 0) return await shared;
22029
- const hit = cache.get(key, "fields");
21082
+ const hit = cache.get(key);
22030
21083
  if (hit !== void 0) return hit;
22031
21084
  }
22032
21085
  const res = await http.request({ method: "GET", path: "/V1.0/Tickets/entityInformation/fields", operation: OP, maxRetries: 0 });
@@ -22034,7 +21087,7 @@ async function readFields(http, fresh) {
22034
21087
  if (!Array.isArray(fields)) {
22035
21088
  throw new AutotaskError("Expected the FieldInformationResultModel envelope { fields: [] }; got a different shape", { code: "INVALID_RESPONSE", category: "server" });
22036
21089
  }
22037
- cache?.set(key, "fields", fields);
21090
+ if (fields.length > 0) cache?.set(key, fields);
22038
21091
  return fields;
22039
21092
  }
22040
21093
  function assumed(allowAssumed, operation) {
@@ -23676,7 +22729,7 @@ function appendWiresNote(wires, note) {
23676
22729
  wires.note = (wires.note ? wires.note + " | " : "") + note;
23677
22730
  }
23678
22731
  function makeFetchCtx(rawHttp, v, contractId, budget) {
23679
- const OP9 = PROFITABILITY_OP;
22732
+ const OP8 = PROFITABILITY_OP;
23680
22733
  const id = parseIdentifier(contractId, "contractId");
23681
22734
  const idNum = typeof id === "number" ? id : Number(id);
23682
22735
  const wires = { issued: 0, requests: 0, budget };
@@ -23688,19 +22741,19 @@ function makeFetchCtx(rawHttp, v, contractId, budget) {
23688
22741
  } };
23689
22742
  const readPart = (path, conditions, fields) => {
23690
22743
  wires.issued += 1;
23691
- return degradable(() => boundedPart(http, path, conditions, v.limit, OP9, fields));
22744
+ return degradable(() => boundedPart(http, path, conditions, v.limit, OP8, fields));
23692
22745
  };
23693
22746
  const truncatedMonths = {};
23694
22747
  const windowedPart = async (name, key, path, cond, fields, dateField) => {
23695
22748
  const first = await readPart(path, cond, fields);
23696
22749
  if (first.absent !== void 0 || !first.hasMore) return { part: stampPart(key, first, cond), rows: first.items };
23697
- const wp = await degradable(() => expandByMonth(http, path, cond, v.limit, OP9, fields, dateField, v.dateFrom, v.dateTo, wires));
22750
+ const wp = await degradable(() => expandByMonth(http, path, cond, v.limit, OP8, fields, dateField, v.dateFrom, v.dateTo, wires));
23698
22751
  if (!("truncatedMonths" in wp)) return { part: stampPart(key, wp, cond), rows: [] };
23699
22752
  const { truncatedMonths: tm, ...part } = wp;
23700
22753
  truncatedMonths[name] = tm;
23701
22754
  return { part, rows: wp.items };
23702
22755
  };
23703
- return { v, OP: OP9, id, idNum, rawHttp, http, wires, windowOn, readPart, windowedPart, truncatedMonths };
22756
+ return { v, OP: OP8, id, idNum, rawHttp, http, wires, windowOn, readPart, windowedPart, truncatedMonths };
23704
22757
  }
23705
22758
 
23706
22759
  // src/resources/special/contracts/profitability.stages.ts
@@ -25332,50 +24385,50 @@ async function queryTimeEntries(_resource, filter, limit, operation, http, curso
25332
24385
  const { items, pageDetails } = unwrapItems(res);
25333
24386
  return { items, hasMore: pageDetails.nextPageUrl != null, nextCursor: pageDetails.nextPageUrl ?? null };
25334
24387
  }
25335
- function pagingOpts(opts, OP9) {
24388
+ function pagingOpts(opts, OP8) {
25336
24389
  if (opts?.countOnly !== void 0 && typeof opts.countOnly !== "boolean") {
25337
- throw new AutotaskConfigError(`${OP9}: countOnly must be a boolean`, { operation: OP9 });
24390
+ throw new AutotaskConfigError(`${OP8}: countOnly must be a boolean`, { operation: OP8 });
25338
24391
  }
25339
24392
  const countOnly = opts?.countOnly === true;
25340
24393
  const cursor = opts?.cursor;
25341
24394
  if (cursor !== void 0 && (typeof cursor !== "string" || cursor.trim() === "")) {
25342
- throw new AutotaskConfigError(`${OP9}: cursor must be the non-empty nextCursor of a previous call`, { operation: OP9 });
24395
+ throw new AutotaskConfigError(`${OP8}: cursor must be the non-empty nextCursor of a previous call`, { operation: OP8 });
25343
24396
  }
25344
24397
  if (cursor !== void 0 && cursor.length > CURSOR_MAX) {
25345
- throw new ResponseRejectedError(`${OP9}: refused the pagination cursor: ${cursor.length} chars is over the ${CURSOR_MAX}-char cap (a vendor nextPageUrl is far shorter)`);
24398
+ throw new ResponseRejectedError(`${OP8}: refused the pagination cursor: ${cursor.length} chars is over the ${CURSOR_MAX}-char cap (a vendor nextPageUrl is far shorter)`);
25346
24399
  }
25347
24400
  if (cursor !== void 0 && countOnly) {
25348
- throw new AutotaskConfigError(`${OP9}: cursor does not apply with countOnly (countOnly reads every page itself)`, { operation: OP9 });
24401
+ throw new AutotaskConfigError(`${OP8}: cursor does not apply with countOnly (countOnly reads every page itself)`, { operation: OP8 });
25349
24402
  }
25350
24403
  const budget = opts?.maxVendorCalls ?? COUNT_BUDGET_DEFAULT;
25351
24404
  if (!Number.isInteger(budget) || budget < 1 || budget > COUNT_BUDGET_MAX) {
25352
- throw new AutotaskConfigError(`${OP9}: maxVendorCalls must be an integer 1-${COUNT_BUDGET_MAX} (got ${String(opts?.maxVendorCalls)})`, { operation: OP9 });
24405
+ throw new AutotaskConfigError(`${OP8}: maxVendorCalls must be an integer 1-${COUNT_BUDGET_MAX} (got ${String(opts?.maxVendorCalls)})`, { operation: OP8 });
25353
24406
  }
25354
24407
  return { ...cursor === void 0 ? {} : { cursor }, countOnly, budget };
25355
24408
  }
25356
- function budgetExceeded(OP9, details, midWalk) {
24409
+ function budgetExceeded(OP8, details, midWalk) {
25357
24410
  const { estimate, budget, total } = details;
25358
24411
  const raise = midWalk ? budget < COUNT_BUDGET_MAX ? `, or pass a maxVendorCalls above ${budget} for headroom past the estimate` : "" : estimate <= COUNT_BUDGET_MAX ? ` or pass maxVendorCalls >= ${estimate}` : "";
25359
24412
  return new AutotaskError(
25360
- midWalk ? `${OP9}: countOnly stopped at the ${budget}-call budget mid-walk: the walk needed more calls than the ${estimate} estimated from the ${total}-entry count (more entries than counted, or an extra page such as an empty continuation page), so the next call, which may be the closing re-count, did not fit; no partial total is returned` : `${OP9}: countOnly needs an estimated ${estimate} vendor calls for ${total} entries (1 count + 1 per ${PAGE} entries + 1 join per 250 + 1 re-count), over the ${budget}-call budget; nothing was read past the count`,
25361
- { code: "BUDGET_EXCEEDED", category: "policy", operation: OP9, details, suggestedAction: `Narrow the dateWorked window (dateFrom/dateTo)${raise}.` }
24413
+ midWalk ? `${OP8}: countOnly stopped at the ${budget}-call budget mid-walk: the walk needed more calls than the ${estimate} estimated from the ${total}-entry count (more entries than counted, or an extra page such as an empty continuation page), so the next call, which may be the closing re-count, did not fit; no partial total is returned` : `${OP8}: countOnly needs an estimated ${estimate} vendor calls for ${total} entries (1 count + 1 per ${PAGE} entries + 1 join per 250 + 1 re-count), over the ${budget}-call budget; nothing was read past the count`,
24414
+ { code: "BUDGET_EXCEEDED", category: "policy", operation: OP8, details, suggestedAction: `Narrow the dateWorked window (dateFrom/dateTo)${raise}.` }
25362
24415
  );
25363
24416
  }
25364
- async function countPostedState(http, filter, OP9, budget, window) {
24417
+ async function countPostedState(http, filter, OP8, budget, window) {
25365
24418
  let issued = 0;
25366
24419
  let estimate = 0;
25367
24420
  let counted = 0;
25368
24421
  const spend = () => {
25369
- if (issued >= budget) throw budgetExceeded(OP9, { estimate, budget, total: counted, issued }, true);
24422
+ if (issued >= budget) throw budgetExceeded(OP8, { estimate, budget, total: counted, issued }, true);
25370
24423
  issued += 1;
25371
24424
  };
25372
24425
  spend();
25373
24426
  counted = unwrapQueryCount(
25374
- await http.request({ method: "POST", idempotent: true, path: "/V1.0/TimeEntries/query/count", body: { filter }, operation: OP9 }),
25375
- OP9
24427
+ await http.request({ method: "POST", idempotent: true, path: "/V1.0/TimeEntries/query/count", body: { filter }, operation: OP8 }),
24428
+ OP8
25376
24429
  );
25377
24430
  estimate = 1 + Math.max(1, Math.ceil(counted / PAGE)) + Math.ceil(counted / 250) + 1;
25378
- if (estimate > budget) throw budgetExceeded(OP9, { estimate, budget, total: counted, issued }, false);
24431
+ if (estimate > budget) throw budgetExceeded(OP8, { estimate, budget, total: counted, issued }, false);
25379
24432
  const states = /* @__PURE__ */ new Map();
25380
24433
  let cursor = null;
25381
24434
  do {
@@ -25385,15 +24438,15 @@ async function countPostedState(http, filter, OP9, budget, window) {
25385
24438
  idempotent: true,
25386
24439
  path: cursor === null ? "/V1.0/TimeEntries/query" : entryCursorPath(http.baseUrl, cursor),
25387
24440
  body: { MaxRecords: PAGE, IncludeFields: ["id"], filter },
25388
- operation: OP9
24441
+ operation: OP8
25389
24442
  });
25390
24443
  const page = unwrapItems(res);
25391
- const joined = await postedStateOf(http, page.items, OP9, spend);
24444
+ const joined = await postedStateOf(http, page.items, OP8, spend);
25392
24445
  if (joined.incomplete) {
25393
- throw new AutotaskError(`${OP9}: countOnly refused: a billing-item join page was truncated (more than 500 billing items for 250 entries), so the posted split cannot be confirmed`, {
24446
+ throw new AutotaskError(`${OP8}: countOnly refused: a billing-item join page was truncated (more than 500 billing items for 250 entries), so the posted split cannot be confirmed`, {
25394
24447
  code: "RESOLUTION_TRUNCATED",
25395
24448
  category: "resolution",
25396
- operation: OP9,
24449
+ operation: OP8,
25397
24450
  details: { issued, budget },
25398
24451
  suggestedAction: "Narrow the dateWorked window, or page it with cursor (rows mode reports unconfirmed entries via hasMore)."
25399
24452
  });
@@ -25403,14 +24456,14 @@ async function countPostedState(http, filter, OP9, budget, window) {
25403
24456
  } while (cursor !== null);
25404
24457
  spend();
25405
24458
  const recounted = unwrapQueryCount(
25406
- await http.request({ method: "POST", idempotent: true, path: "/V1.0/TimeEntries/query/count", body: { filter }, operation: OP9 }),
25407
- OP9
24459
+ await http.request({ method: "POST", idempotent: true, path: "/V1.0/TimeEntries/query/count", body: { filter }, operation: OP8 }),
24460
+ OP8
25408
24461
  );
25409
24462
  if (states.size !== counted && states.size !== recounted) {
25410
- throw new AutotaskError(`${OP9}: countOnly read ${states.size} distinct entries but the window counted ${counted} before the walk and ${recounted} after it (a page repeated or dropped entries, or the window changed mid-walk); no total is returned. Retry the call`, {
24463
+ throw new AutotaskError(`${OP8}: countOnly read ${states.size} distinct entries but the window counted ${counted} before the walk and ${recounted} after it (a page repeated or dropped entries, or the window changed mid-walk); no total is returned. Retry the call`, {
25411
24464
  code: "INVALID_RESPONSE",
25412
24465
  category: "server",
25413
- operation: OP9,
24466
+ operation: OP8,
25414
24467
  details: { reason: "count_mismatch", streamed: states.size, counted, recounted, issued, budget },
25415
24468
  suggestedAction: "Retry the call; a window that changes during the walk can fail or pass depending on timing."
25416
24469
  });
@@ -25467,13 +24520,13 @@ async function postedStateQuery(_resource, mode, http, opts) {
25467
24520
  return { items, hasMore: read.hasMore || incomplete, window, nextCursor: read.nextCursor, unconfirmed, approvedCount, unapprovedCount: items.length - approvedCount };
25468
24521
  }
25469
24522
  async function postedWithin(_resource, from, to, http, opts, opLabel = "time_entries.postedWithin") {
25470
- const OP9 = opLabel;
25471
- const paging = pagingOpts(opts, OP9);
25472
- if (opts?.tz !== void 0) validateZone(opts.tz, OP9);
25473
- const fromB = customRangeDay(from, "from", void 0, OP9);
25474
- const toB = customRangeDay(to, "to", void 0, OP9);
24523
+ const OP8 = opLabel;
24524
+ const paging = pagingOpts(opts, OP8);
24525
+ if (opts?.tz !== void 0) validateZone(opts.tz, OP8);
24526
+ const fromB = customRangeDay(from, "from", void 0, OP8);
24527
+ const toB = customRangeDay(to, "to", void 0, OP8);
25475
24528
  if (fromB.ms > toB.ms) {
25476
- throw new AutotaskConfigError(`${OP9}: from (${iso2(fromB.ms)}) must not be after to (${iso2(toB.ms)})`, { operation: OP9 });
24529
+ throw new AutotaskConfigError(`${OP8}: from (${iso2(fromB.ms)}) must not be after to (${iso2(toB.ms)})`, { operation: OP8 });
25477
24530
  }
25478
24531
  const windowToMs = toB.ms + DAY_MS2 - 1;
25479
24532
  const filter = [
@@ -25483,9 +24536,9 @@ async function postedWithin(_resource, from, to, http, opts, opLabel = "time_ent
25483
24536
  if (opts?.ticketID !== void 0) filter.push({ field: "ticketID", op: "eq", value: opts.ticketID });
25484
24537
  if (opts?.resourceID !== void 0) filter.push({ field: "resourceID", op: "eq", value: opts.resourceID });
25485
24538
  const window = { from: iso2(fromB.ms), to: iso2(windowToMs) };
25486
- if (paging.countOnly) return countPostedState(http, filter, OP9, paging.budget, window);
25487
- const { items, hasMore, nextCursor } = await queryTimeEntries(_resource, filter, clampWindowLimit(opts?.limit), OP9, http, paging.cursor);
25488
- const { states, incomplete } = await postedStateOf(http, items, OP9);
24539
+ if (paging.countOnly) return countPostedState(http, filter, OP8, paging.budget, window);
24540
+ const { items, hasMore, nextCursor } = await queryTimeEntries(_resource, filter, clampWindowLimit(opts?.limit), OP8, http, paging.cursor);
24541
+ const { states, incomplete } = await postedStateOf(http, items, OP8);
25489
24542
  let postedCount = 0;
25490
24543
  let unpostedCount = 0;
25491
24544
  for (const state of states.values()) {
@@ -26255,103 +25308,6 @@ async function approve(resource, id, opts = {}, http) {
26255
25308
  };
26256
25309
  }
26257
25310
 
26258
- // src/resources/special/time_entries/recentTickets.ts
26259
- var OP8 = "time_entries.recentTickets";
26260
- var DAY_MS3 = 864e5;
26261
- var TICKET_CHUNK = 100;
26262
- var TICKET_FIELDS2 = ["id", "ticketNumber", "title", "status", "assignedResourceID", "companyID"];
26263
- function positiveId2(value, name) {
26264
- const n = typeof value === "string" && /^\d+$/.test(value.trim()) ? Number(value) : value;
26265
- if (typeof n !== "number" || !Number.isSafeInteger(n) || n < 1) {
26266
- throw new AutotaskConfigError(`${OP8}: ${name} must be a positive integer id (got ${String(value)})`, { operation: OP8 });
26267
- }
26268
- return n;
26269
- }
26270
- async function recentTickets(_resource, from, to, http, opts) {
26271
- if (opts === void 0 || opts === null || typeof opts !== "object") {
26272
- throw new AutotaskConfigError(`${OP8}: opts { resourceID, companyID?, tz?, limit? } is required`, { operation: OP8 });
26273
- }
26274
- const resourceID = positiveId2(opts.resourceID, "resourceID");
26275
- const companyID = opts.companyID === void 0 ? void 0 : positiveId2(opts.companyID, "companyID");
26276
- if (opts.tz !== void 0) validateZone(opts.tz, OP8);
26277
- const fromB = customRangeDay(from, "from", void 0, OP8);
26278
- const toB = customRangeDay(to, "to", void 0, OP8);
26279
- if (fromB.ms > toB.ms) {
26280
- throw new AutotaskConfigError(`${OP8}: from (${isoUtc(fromB.ms)}) must not be after to (${isoUtc(toB.ms)})`, { operation: OP8 });
26281
- }
26282
- const windowToMs = toB.ms + DAY_MS3 - 1;
26283
- const { items: entries, hasMore } = await queryTimeEntries(
26284
- _resource,
26285
- [
26286
- { field: "dateWorked", op: "gte", value: isoUtc(fromB.ms) },
26287
- { field: "dateWorked", op: "lte", value: isoUtc(windowToMs) },
26288
- { field: "resourceID", op: "eq", value: resourceID }
26289
- ],
26290
- clampWindowLimit(opts.limit),
26291
- OP8,
26292
- http
26293
- );
26294
- const groups = /* @__PURE__ */ new Map();
26295
- let entriesWithoutTicket = 0;
26296
- for (const e of entries) {
26297
- if (typeof e.ticketID !== "number") {
26298
- entriesWithoutTicket += 1;
26299
- continue;
26300
- }
26301
- const g = groups.get(e.ticketID) ?? { entryCount: 0, totalHours: 0, lastWorked: "" };
26302
- g.entryCount += 1;
26303
- g.totalHours += e.hoursWorked ?? 0;
26304
- if ((e.dateWorked ?? "") > g.lastWorked) g.lastWorked = e.dateWorked ?? "";
26305
- groups.set(e.ticketID, g);
26306
- }
26307
- const ids2 = [...groups.keys()];
26308
- const tickets = /* @__PURE__ */ new Map();
26309
- for (let c = 0; c < ids2.length; c += TICKET_CHUNK) {
26310
- const chunk = ids2.slice(c, c + TICKET_CHUNK);
26311
- const filter = [{ field: "id", op: "in", value: chunk }];
26312
- const res = await http.request({
26313
- method: "POST",
26314
- idempotent: true,
26315
- path: "/V1.0/Tickets/query",
26316
- body: { MaxRecords: TICKET_CHUNK, filter, IncludeFields: TICKET_FIELDS2 },
26317
- operation: OP8
26318
- });
26319
- for (const t of unwrapItems(res, OP8).items) if (typeof t.id === "number") tickets.set(t.id, t);
26320
- }
26321
- const items = [];
26322
- const unresolvedTicketIDs = [];
26323
- let excludedTickets = 0;
26324
- for (const [ticketID, g] of groups) {
26325
- const t = tickets.get(ticketID);
26326
- if (t === void 0) unresolvedTicketIDs.push(ticketID);
26327
- if (companyID !== void 0 && t?.companyID !== companyID) {
26328
- if (t !== void 0) excludedTickets += 1;
26329
- continue;
26330
- }
26331
- items.push({
26332
- ticketID,
26333
- ...t?.ticketNumber !== void 0 ? { ticketNumber: t.ticketNumber } : {},
26334
- ...t?.title !== void 0 ? { title: t.title } : {},
26335
- ...t?.status !== void 0 ? { status: t.status } : {},
26336
- ...t?.assignedResourceID !== void 0 ? { assignedResourceID: t.assignedResourceID } : {},
26337
- ...t?.companyID !== void 0 ? { companyID: t.companyID } : {},
26338
- entryCount: g.entryCount,
26339
- totalHours: Math.round(g.totalHours * 100) / 100,
26340
- lastWorked: g.lastWorked
26341
- });
26342
- }
26343
- items.sort((a, b) => a.lastWorked < b.lastWorked ? 1 : a.lastWorked > b.lastWorked ? -1 : a.ticketID - b.ticketID);
26344
- return {
26345
- items,
26346
- entriesRead: entries.length,
26347
- entriesWithoutTicket,
26348
- unresolvedTicketIDs,
26349
- ...companyID !== void 0 ? { excludedTickets } : {},
26350
- window: { from: isoUtc(fromB.ms), to: isoUtc(windowToMs) },
26351
- truncated: hasMore
26352
- };
26353
- }
26354
-
26355
25311
  // src/resources/time_entries.ts
26356
25312
  var TimeEntriesResource = class extends BaseResource {
26357
25313
  constructor(http, pageSize) {
@@ -26483,11 +25439,6 @@ var TimeEntriesResource = class extends BaseResource {
26483
25439
  postedWithin(from, to, opts) {
26484
25440
  return postedWithin(this, from, to, this.http, opts);
26485
25441
  }
26486
- /** Node-parity special op (hand-written in src/resources/special/time_entries.ts).
26487
- * @deprecated Since 0.38.0, removed in the next minor. Use operations.aggregate(client, 'time_entries.query', [{ field: 'resourceID', op: 'eq', value: R }, { field: 'dateWorked', op: 'gte', value: FROM }, { field: 'dateWorked', op: 'lte', value: TO }], { groupBy: ['ticketID'], sum: ['hoursWorked'] }) — group keys carry ticketIDName; add { field: 'ticket.companyID', op: 'eq', value: C } to scope by company. */
26488
- recentTickets(from, to, opts) {
26489
- return recentTickets(this, from, to, this.http, opts);
26490
- }
26491
25442
  /** Node-parity special op (hand-written in src/resources/special/time_entries.ts). */
26492
25443
  today(opts) {
26493
25444
  return windowQuery3(this, "today", this.http, opts);
@@ -26519,7 +25470,7 @@ export {
26519
25470
  ServerError,
26520
25471
  UnexpectedContentTypeError,
26521
25472
  EmptyResponseError,
26522
- CircuitBreakerError,
25473
+ MaintenanceError,
26523
25474
  HostPolicyDeniedError,
26524
25475
  ResolutionError,
26525
25476
  PaginationLimitError,
@@ -26547,7 +25498,12 @@ export {
26547
25498
  RecoveryTruncatedError,
26548
25499
  MoveRefusedError,
26549
25500
  READ_CACHE_MAX_ENTRIES,
26550
- ReadCache,
25501
+ REFERENCE_TTL_MS,
25502
+ REFERENCE_ENTITIES,
25503
+ FIELD_CACHE_KINDS,
25504
+ fieldKey,
25505
+ readTtlFor,
25506
+ TtlCache,
26551
25507
  ZONE_CATALOG,
26552
25508
  ZONES,
26553
25509
  DEFAULT_ZONE,
@@ -26567,31 +25523,11 @@ export {
26567
25523
  DEFAULT_MAX_SCAN_PAGES,
26568
25524
  DEFAULT_READ_CACHE_TTL_MS,
26569
25525
  DEFAULT_FIELD_CACHE_TTL_MS,
26570
- DEFAULT_RESOURCE_NAME_CACHE_TTL_MS,
26571
25526
  hasSurroundingQuotes,
26572
25527
  credentialShapeProblem,
26573
25528
  CREDENTIAL_ENV_LOAD_ACTION,
26574
25529
  MIN_PREFIX_SUMMARY_LENGTH,
26575
25530
  credentialValueSummary,
26576
- FIELD_CACHE_KINDS,
26577
- DEFAULT_CIRCUIT_BREAKER_WINDOW_MS,
26578
- DEFAULT_CIRCUIT_BREAKER_FAILURE_THRESHOLD,
26579
- DEFAULT_CIRCUIT_BREAKER_OPEN_TIMEOUT_MS,
26580
- DEFAULT_CIRCUIT_BREAKER_SUCCESSES_TO_CLOSE,
26581
- DEFAULT_CIRCUIT_BREAKER_MAX_ENTRIES,
26582
- InMemoryCircuitBreakerStore,
26583
- defaultCircuitBreakerStore,
26584
- resetDefaultCircuitBreakerStore,
26585
- buildBreakerKey,
26586
- isBreakerFailure,
26587
- DEFAULT_COOLDOWN_MAX_MS,
26588
- DEFAULT_COOLDOWN_DEFAULT_MS,
26589
- DEFAULT_COOLDOWN_MAX_ENTRIES,
26590
- InMemoryCooldownStore,
26591
- defaultCooldownStore,
26592
- resetDefaultCooldownStore,
26593
- buildTenantKey,
26594
- cooldownDurationMs,
26595
25531
  resolveCredentials,
26596
25532
  buildReadCache,
26597
25533
  resolveConfig,