@onlyflows/servicenow-mcp 2.2.0-dev.5 → 2.2.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 (251) hide show
  1. package/.env.example +6 -3
  2. package/CHANGELOG.md +312 -0
  3. package/README.md +504 -101
  4. package/dist/atf-form.d.ts +3 -15
  5. package/dist/atf-form.d.ts.map +1 -1
  6. package/dist/atf-result-cache.d.ts +23 -59
  7. package/dist/atf-result-cache.d.ts.map +1 -1
  8. package/dist/auth.d.ts +1 -0
  9. package/dist/auth.d.ts.map +1 -1
  10. package/dist/auth.js +17 -0
  11. package/dist/auth.js.map +1 -1
  12. package/dist/batch-limits.d.ts +18 -0
  13. package/dist/batch-limits.d.ts.map +1 -0
  14. package/dist/batch-limits.js +21 -0
  15. package/dist/batch-limits.js.map +1 -0
  16. package/dist/bounded-input.d.ts +49 -0
  17. package/dist/bounded-input.d.ts.map +1 -0
  18. package/dist/bounded-input.js +81 -0
  19. package/dist/bounded-input.js.map +1 -0
  20. package/dist/client.d.ts +25 -0
  21. package/dist/client.d.ts.map +1 -1
  22. package/dist/client.js +92 -18
  23. package/dist/client.js.map +1 -1
  24. package/dist/command-resolution.d.ts +53 -0
  25. package/dist/command-resolution.d.ts.map +1 -0
  26. package/dist/command-resolution.js +154 -0
  27. package/dist/command-resolution.js.map +1 -0
  28. package/dist/encoded-query-policy.d.ts +11 -0
  29. package/dist/encoded-query-policy.d.ts.map +1 -1
  30. package/dist/encoded-query-policy.js +10 -1
  31. package/dist/encoded-query-policy.js.map +1 -1
  32. package/dist/field-policy.d.ts +82 -3
  33. package/dist/field-policy.d.ts.map +1 -1
  34. package/dist/field-policy.js +609 -80
  35. package/dist/field-policy.js.map +1 -1
  36. package/dist/html-response.d.ts +34 -0
  37. package/dist/html-response.d.ts.map +1 -0
  38. package/dist/html-response.js +72 -0
  39. package/dist/html-response.js.map +1 -0
  40. package/dist/http-runtime.d.ts.map +1 -1
  41. package/dist/http-runtime.js +8 -0
  42. package/dist/http-runtime.js.map +1 -1
  43. package/dist/incident-journal-policy.d.ts +27 -5
  44. package/dist/incident-journal-policy.d.ts.map +1 -1
  45. package/dist/incident-journal-policy.js +34 -21
  46. package/dist/incident-journal-policy.js.map +1 -1
  47. package/dist/json-shape-limits.d.ts +71 -0
  48. package/dist/json-shape-limits.d.ts.map +1 -0
  49. package/dist/json-shape-limits.js +131 -0
  50. package/dist/json-shape-limits.js.map +1 -0
  51. package/dist/metadata-cache.d.ts +46 -21
  52. package/dist/metadata-cache.d.ts.map +1 -1
  53. package/dist/metadata-cache.js +228 -195
  54. package/dist/metadata-cache.js.map +1 -1
  55. package/dist/policy-card.d.ts +131 -0
  56. package/dist/policy-card.d.ts.map +1 -0
  57. package/dist/policy-card.js +409 -0
  58. package/dist/policy-card.js.map +1 -0
  59. package/dist/profile-admin.d.ts.map +1 -1
  60. package/dist/profile-admin.js +3 -0
  61. package/dist/profile-admin.js.map +1 -1
  62. package/dist/profile-manager.d.ts +17 -3
  63. package/dist/profile-manager.d.ts.map +1 -1
  64. package/dist/profile-manager.js +98 -6
  65. package/dist/profile-manager.js.map +1 -1
  66. package/dist/record-identifier-policy.d.ts +2 -8
  67. package/dist/record-identifier-policy.d.ts.map +1 -1
  68. package/dist/risky-grants.d.ts +25 -0
  69. package/dist/risky-grants.d.ts.map +1 -0
  70. package/dist/risky-grants.js +77 -0
  71. package/dist/risky-grants.js.map +1 -0
  72. package/dist/server.d.ts.map +1 -1
  73. package/dist/server.js +74 -0
  74. package/dist/server.js.map +1 -1
  75. package/dist/setup-prompts.js +1 -0
  76. package/dist/setup-prompts.js.map +1 -1
  77. package/dist/setup.d.ts +8 -1
  78. package/dist/setup.d.ts.map +1 -1
  79. package/dist/setup.js +492 -111
  80. package/dist/setup.js.map +1 -1
  81. package/dist/stdio-runtime.d.ts +15 -0
  82. package/dist/stdio-runtime.d.ts.map +1 -1
  83. package/dist/stdio-runtime.js +60 -0
  84. package/dist/stdio-runtime.js.map +1 -1
  85. package/dist/structured-query.d.ts +100 -115
  86. package/dist/structured-query.d.ts.map +1 -1
  87. package/dist/structured-query.js +132 -16
  88. package/dist/structured-query.js.map +1 -1
  89. package/dist/table-policy.d.ts +10 -4
  90. package/dist/table-policy.d.ts.map +1 -1
  91. package/dist/table-policy.js +1 -1
  92. package/dist/table-policy.js.map +1 -1
  93. package/dist/tool-error.d.ts +18 -0
  94. package/dist/tool-error.d.ts.map +1 -1
  95. package/dist/tool-error.js +69 -0
  96. package/dist/tool-error.js.map +1 -1
  97. package/dist/tool-table-access.d.ts.map +1 -1
  98. package/dist/tool-table-access.js +32 -2
  99. package/dist/tool-table-access.js.map +1 -1
  100. package/dist/tools/aggregate.d.ts +13 -19
  101. package/dist/tools/aggregate.d.ts.map +1 -1
  102. package/dist/tools/aggregate.js +2 -3
  103. package/dist/tools/aggregate.js.map +1 -1
  104. package/dist/tools/all-fields-cap.d.ts.map +1 -1
  105. package/dist/tools/all-fields-cap.js +3 -38
  106. package/dist/tools/all-fields-cap.js.map +1 -1
  107. package/dist/tools/atf-author-module.d.ts +28 -7
  108. package/dist/tools/atf-author-module.d.ts.map +1 -1
  109. package/dist/tools/atf-author-module.js +4 -2
  110. package/dist/tools/atf-author-module.js.map +1 -1
  111. package/dist/tools/atf-contracts.d.ts +135 -829
  112. package/dist/tools/atf-contracts.d.ts.map +1 -1
  113. package/dist/tools/atf-shared.js +2 -2
  114. package/dist/tools/atf-shared.js.map +1 -1
  115. package/dist/tools/atf-step-catalog.d.ts +3 -7
  116. package/dist/tools/atf-step-catalog.d.ts.map +1 -1
  117. package/dist/tools/atf-step-catalog.js +12 -5
  118. package/dist/tools/atf-step-catalog.js.map +1 -1
  119. package/dist/tools/atf.d.ts +8 -24
  120. package/dist/tools/atf.d.ts.map +1 -1
  121. package/dist/tools/atf.js +2 -2
  122. package/dist/tools/atf.js.map +1 -1
  123. package/dist/tools/attach.d.ts +6 -22
  124. package/dist/tools/attach.d.ts.map +1 -1
  125. package/dist/tools/batch.d.ts +18 -71
  126. package/dist/tools/batch.d.ts.map +1 -1
  127. package/dist/tools/batch.js +544 -96
  128. package/dist/tools/batch.js.map +1 -1
  129. package/dist/tools/catalog.d.ts +2 -2
  130. package/dist/tools/catalog.d.ts.map +1 -1
  131. package/dist/tools/catalog.js +7 -1
  132. package/dist/tools/catalog.js.map +1 -1
  133. package/dist/tools/codesearch.d.ts +1 -13
  134. package/dist/tools/codesearch.d.ts.map +1 -1
  135. package/dist/tools/create-module.d.ts +9 -14
  136. package/dist/tools/create-module.d.ts.map +1 -1
  137. package/dist/tools/create-module.js +4 -8
  138. package/dist/tools/create-module.js.map +1 -1
  139. package/dist/tools/delete.d.ts +1 -9
  140. package/dist/tools/delete.d.ts.map +1 -1
  141. package/dist/tools/delete.js +2 -3
  142. package/dist/tools/delete.js.map +1 -1
  143. package/dist/tools/discover.d.ts +6 -14
  144. package/dist/tools/discover.d.ts.map +1 -1
  145. package/dist/tools/flow-view-contracts.d.ts +1023 -0
  146. package/dist/tools/flow-view-contracts.d.ts.map +1 -0
  147. package/dist/tools/flow-view-contracts.js +570 -0
  148. package/dist/tools/flow-view-contracts.js.map +1 -0
  149. package/dist/tools/flow-view-graph.d.ts +86 -0
  150. package/dist/tools/flow-view-graph.d.ts.map +1 -0
  151. package/dist/tools/flow-view-graph.js +993 -0
  152. package/dist/tools/flow-view-graph.js.map +1 -0
  153. package/dist/tools/flow-view-gzip.d.ts +52 -0
  154. package/dist/tools/flow-view-gzip.d.ts.map +1 -0
  155. package/dist/tools/flow-view-gzip.js +179 -0
  156. package/dist/tools/flow-view-gzip.js.map +1 -0
  157. package/dist/tools/flow-view-mermaid.d.ts +37 -0
  158. package/dist/tools/flow-view-mermaid.d.ts.map +1 -0
  159. package/dist/tools/flow-view-mermaid.js +337 -0
  160. package/dist/tools/flow-view-mermaid.js.map +1 -0
  161. package/dist/tools/flow-view-module.d.ts +61 -0
  162. package/dist/tools/flow-view-module.d.ts.map +1 -0
  163. package/dist/tools/flow-view-module.js +378 -0
  164. package/dist/tools/flow-view-module.js.map +1 -0
  165. package/dist/tools/flow-view-policy.d.ts +106 -0
  166. package/dist/tools/flow-view-policy.d.ts.map +1 -0
  167. package/dist/tools/flow-view-policy.js +461 -0
  168. package/dist/tools/flow-view-policy.js.map +1 -0
  169. package/dist/tools/flow-view-renderers.d.ts +68 -0
  170. package/dist/tools/flow-view-renderers.d.ts.map +1 -0
  171. package/dist/tools/flow-view-renderers.js +513 -0
  172. package/dist/tools/flow-view-renderers.js.map +1 -0
  173. package/dist/tools/flow-view-table.d.ts +115 -0
  174. package/dist/tools/flow-view-table.d.ts.map +1 -0
  175. package/dist/tools/flow-view-table.js +1002 -0
  176. package/dist/tools/flow-view-table.js.map +1 -0
  177. package/dist/tools/get-module.d.ts +36 -42
  178. package/dist/tools/get-module.d.ts.map +1 -1
  179. package/dist/tools/health.d.ts +9 -6
  180. package/dist/tools/health.d.ts.map +1 -1
  181. package/dist/tools/incident-journal-module.d.ts +8 -7
  182. package/dist/tools/incident-journal-module.d.ts.map +1 -1
  183. package/dist/tools/index.d.ts +4 -4
  184. package/dist/tools/index.d.ts.map +1 -1
  185. package/dist/tools/index.js +43 -6
  186. package/dist/tools/index.js.map +1 -1
  187. package/dist/tools/markdown.d.ts +27 -0
  188. package/dist/tools/markdown.d.ts.map +1 -1
  189. package/dist/tools/markdown.js +104 -1
  190. package/dist/tools/markdown.js.map +1 -1
  191. package/dist/tools/nl.d.ts +1 -11
  192. package/dist/tools/nl.d.ts.map +1 -1
  193. package/dist/tools/profile.d.ts +1 -1
  194. package/dist/tools/profile.d.ts.map +1 -1
  195. package/dist/tools/profile.js +19 -1
  196. package/dist/tools/profile.js.map +1 -1
  197. package/dist/tools/query-module.d.ts +59 -71
  198. package/dist/tools/query-module.d.ts.map +1 -1
  199. package/dist/tools/query-module.js +2 -2
  200. package/dist/tools/query-module.js.map +1 -1
  201. package/dist/tools/record-write-shared.d.ts.map +1 -1
  202. package/dist/tools/record-write-shared.js +19 -2
  203. package/dist/tools/record-write-shared.js.map +1 -1
  204. package/dist/tools/relationships.d.ts +6 -22
  205. package/dist/tools/relationships.d.ts.map +1 -1
  206. package/dist/tools/result-envelope.d.ts +2255 -1357
  207. package/dist/tools/result-envelope.d.ts.map +1 -1
  208. package/dist/tools/result-envelope.js +24 -2
  209. package/dist/tools/result-envelope.js.map +1 -1
  210. package/dist/tools/schema-module.d.ts +36 -21
  211. package/dist/tools/schema-module.d.ts.map +1 -1
  212. package/dist/tools/schema-module.js +106 -65
  213. package/dist/tools/schema-module.js.map +1 -1
  214. package/dist/tools/script.d.ts +1 -11
  215. package/dist/tools/script.d.ts.map +1 -1
  216. package/dist/tools/syslog.d.ts +11 -18
  217. package/dist/tools/syslog.d.ts.map +1 -1
  218. package/dist/tools/syslog.js +2 -3
  219. package/dist/tools/syslog.js.map +1 -1
  220. package/dist/tools/table-hierarchy.d.ts +35 -0
  221. package/dist/tools/table-hierarchy.d.ts.map +1 -0
  222. package/dist/tools/table-hierarchy.js +74 -0
  223. package/dist/tools/table-hierarchy.js.map +1 -0
  224. package/dist/tools/tool-module.d.ts +40 -15
  225. package/dist/tools/tool-module.d.ts.map +1 -1
  226. package/dist/tools/tool-module.js +755 -205
  227. package/dist/tools/tool-module.js.map +1 -1
  228. package/dist/tools/update-module.d.ts +11 -17
  229. package/dist/tools/update-module.d.ts.map +1 -1
  230. package/dist/tools/update-module.js +10 -12
  231. package/dist/tools/update-module.js.map +1 -1
  232. package/dist/version.d.ts +1 -1
  233. package/dist/version.d.ts.map +1 -1
  234. package/dist/version.js +1 -1
  235. package/dist/version.js.map +1 -1
  236. package/dist/write-value-policy.d.ts +20 -12
  237. package/dist/write-value-policy.d.ts.map +1 -1
  238. package/dist/write-value-policy.js +179 -67
  239. package/dist/write-value-policy.js.map +1 -1
  240. package/docs/ADDING-TOOLS.md +22 -13
  241. package/docs/CLIENT-SETUP.md +110 -52
  242. package/docs/CROSS-CLIENT-RELEASE-MATRIX.md +2 -2
  243. package/docs/FLOW-VIEW.md +214 -0
  244. package/docs/PRODUCTION-SECURITY.md +154 -25
  245. package/docs/RELEASE-VALIDATION.md +2 -2
  246. package/docs/TESTING-OAUTH.md +1 -1
  247. package/docs/V2-MIGRATION.md +404 -30
  248. package/package.json +21 -6
  249. package/scripts/release-validate.mjs +56 -0
  250. package/server.json +22 -0
  251. package/tools/inspector/package-lock.json +163 -201
@@ -1,19 +1,41 @@
1
- /** Shared append-only incident journal validation and migration policy. */
1
+ /**
2
+ * Shared journal content bounds and the dedicated incident journal tools'
3
+ * argument policy.
4
+ *
5
+ * The content schema bounds every journal write: the dedicated incident
6
+ * tools, and `comments`/`work_notes` written through the generic write tools
7
+ * on any table (see write-value-policy.ts). Generic journal writes are no
8
+ * longer rejected by name; the configured field policy decides whether a
9
+ * profile may write them.
10
+ */
2
11
  import { z } from "zod";
3
12
  export declare const INCIDENT_JOURNAL_MAX_CHARACTERS = 8000;
4
13
  export declare const INCIDENT_JOURNAL_MAX_UTF8_BYTES = 16384;
5
14
  export type IncidentJournalField = "comments" | "work_notes";
6
- export declare const incidentJournalContentSchema: z.ZodEffects<z.ZodString, string, string>;
15
+ /**
16
+ * True for a canonical journal field name. A write to one appends an entry,
17
+ * so the value policy bounds it as journal text and the HTTP client never
18
+ * re-sends it after the request may have reached the instance.
19
+ */
20
+ export declare function isJournalFieldName(field: string): boolean;
21
+ export declare const incidentJournalContentSchema: z.ZodString;
7
22
  export declare class IncidentJournalPolicyError extends Error {
23
+ /**
24
+ * `generic_journal_update` is no longer issued: generic journal writes are
25
+ * decided by field policy. The reason stays in the type so the dispatcher's
26
+ * existing classification branches keep compiling.
27
+ */
8
28
  readonly reason: "generic_journal_update" | "invalid_journal_content";
9
29
  readonly field?: IncidentJournalField;
10
30
  constructor(reason: "generic_journal_update" | "invalid_journal_content", field?: IncidentJournalField);
11
31
  }
12
32
  export declare function isIncidentJournalPolicyError(error: unknown): error is IncidentJournalPolicyError;
13
- /** Safe fixed guidance; caller-controlled journal text is never interpolated. */
33
+ /**
34
+ * Safe fixed guidance; caller-controlled journal text is never interpolated.
35
+ * Only the dispatcher's `generic_journal_update` branch uses it, and nothing
36
+ * issues that reason any more.
37
+ */
14
38
  export declare function incidentJournalMigrationMessage(field: IncidentJournalField, tool?: string): string;
15
- /** Reject journal keys in generic writes without reading any payload values. */
16
- export declare function rejectGenericIncidentJournalFields(payload: unknown): void;
17
39
  /** Defense-in-depth normalization for the fixed incident journal modules. */
18
40
  export declare function prepareIncidentJournalArguments(args: Readonly<Record<string, unknown>>): Readonly<{
19
41
  sys_id: string;
@@ -1 +1 @@
1
- {"version":3,"file":"incident-journal-policy.d.ts","sourceRoot":"","sources":["../src/incident-journal-policy.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAG3E,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,eAAO,MAAM,+BAA+B,OAAQ,CAAC;AACrD,eAAO,MAAM,+BAA+B,QAAS,CAAC;AAEtD,MAAM,MAAM,oBAAoB,GAAG,UAAU,GAAG,YAAY,CAAC;AAY7D,eAAO,MAAM,4BAA4B,2CA0CtC,CAAC;AAEJ,qBAAa,0BAA2B,SAAQ,KAAK;IACnD,QAAQ,CAAC,MAAM,EAAE,wBAAwB,GAAG,yBAAyB,CAAC;IACtE,QAAQ,CAAC,KAAK,CAAC,EAAE,oBAAoB,CAAC;gBAGpC,MAAM,EAAE,wBAAwB,GAAG,yBAAyB,EAC5D,KAAK,CAAC,EAAE,oBAAoB;CAS/B;AAED,wBAAgB,4BAA4B,CAC1C,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,0BAA0B,CAMrC;AAED,iFAAiF;AACjF,wBAAgB,+BAA+B,CAC7C,KAAK,EAAE,oBAAoB,EAC3B,IAAI,CAAC,EAAE,MAAM,GACZ,MAAM,CAYR;AAED,gFAAgF;AAChF,wBAAgB,kCAAkC,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAgBzE;AAED,6EAA6E;AAC7E,wBAAgB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,CAAC,CAO/C"}
@@ -1,16 +1,37 @@
1
1
  "use strict";
2
- /** Shared append-only incident journal validation and migration policy. */
2
+ /**
3
+ * Shared journal content bounds and the dedicated incident journal tools'
4
+ * argument policy.
5
+ *
6
+ * The content schema bounds every journal write: the dedicated incident
7
+ * tools, and `comments`/`work_notes` written through the generic write tools
8
+ * on any table (see write-value-policy.ts). Generic journal writes are no
9
+ * longer rejected by name; the configured field policy decides whether a
10
+ * profile may write them.
11
+ */
3
12
  Object.defineProperty(exports, "__esModule", { value: true });
4
13
  exports.IncidentJournalPolicyError = exports.incidentJournalContentSchema = exports.INCIDENT_JOURNAL_MAX_UTF8_BYTES = exports.INCIDENT_JOURNAL_MAX_CHARACTERS = void 0;
14
+ exports.isJournalFieldName = isJournalFieldName;
5
15
  exports.isIncidentJournalPolicyError = isIncidentJournalPolicyError;
6
16
  exports.incidentJournalMigrationMessage = incidentJournalMigrationMessage;
7
- exports.rejectGenericIncidentJournalFields = rejectGenericIncidentJournalFields;
8
17
  exports.prepareIncidentJournalArguments = prepareIncidentJournalArguments;
9
- const node_util_1 = require("node:util");
10
18
  const zod_1 = require("zod");
11
19
  const servicenow_identifiers_js_1 = require("./servicenow-identifiers.js");
12
20
  exports.INCIDENT_JOURNAL_MAX_CHARACTERS = 8_000;
13
21
  exports.INCIDENT_JOURNAL_MAX_UTF8_BYTES = 16_384;
22
+ /** Journal fields share these names on incident and every other task table. */
23
+ const JOURNAL_FIELD_NAMES = new Set([
24
+ "comments",
25
+ "work_notes",
26
+ ]);
27
+ /**
28
+ * True for a canonical journal field name. A write to one appends an entry,
29
+ * so the value policy bounds it as journal text and the HTTP client never
30
+ * re-sends it after the request may have reached the instance.
31
+ */
32
+ function isJournalFieldName(field) {
33
+ return JOURNAL_FIELD_NAMES.has(field);
34
+ }
14
35
  const JOURNAL_TOOLS = Object.freeze({
15
36
  comments: "sn_incident_add_comment",
16
37
  work_notes: "sn_incident_add_work_note",
@@ -57,6 +78,11 @@ exports.incidentJournalContentSchema = zod_1.z
57
78
  .describe(`Journal text; 1-${exports.INCIDENT_JOURNAL_MAX_CHARACTERS} characters and at most ` +
58
79
  `${exports.INCIDENT_JOURNAL_MAX_UTF8_BYTES} UTF-8 bytes.`);
59
80
  class IncidentJournalPolicyError extends Error {
81
+ /**
82
+ * `generic_journal_update` is no longer issued: generic journal writes are
83
+ * decided by field policy. The reason stays in the type so the dispatcher's
84
+ * existing classification branches keep compiling.
85
+ */
60
86
  reason;
61
87
  field;
62
88
  constructor(reason, field) {
@@ -74,7 +100,11 @@ function isIncidentJournalPolicyError(error) {
74
100
  error !== null &&
75
101
  ISSUED_INCIDENT_JOURNAL_POLICY_ERRORS.has(error));
76
102
  }
77
- /** Safe fixed guidance; caller-controlled journal text is never interpolated. */
103
+ /**
104
+ * Safe fixed guidance; caller-controlled journal text is never interpolated.
105
+ * Only the dispatcher's `generic_journal_update` branch uses it, and nothing
106
+ * issues that reason any more.
107
+ */
78
108
  function incidentJournalMigrationMessage(field, tool) {
79
109
  const rejected = typeof tool === "string" && tool.trim() !== ""
80
110
  ? `${tool.trim()} cannot write append-only incident field ${field}.`
@@ -86,23 +116,6 @@ function incidentJournalMigrationMessage(field, tool) {
86
116
  : `Use ${JOURNAL_TOOLS[field]} with sys_id and content.`;
87
117
  return `${rejected} ${remedy}`;
88
118
  }
89
- /** Reject journal keys in generic writes without reading any payload values. */
90
- function rejectGenericIncidentJournalFields(payload) {
91
- if (typeof payload !== "object" ||
92
- payload === null ||
93
- Array.isArray(payload) ||
94
- node_util_1.types.isProxy(payload)) {
95
- return;
96
- }
97
- for (const candidate of Reflect.ownKeys(payload)) {
98
- if (typeof candidate !== "string")
99
- continue;
100
- const field = candidate.trim().toLowerCase();
101
- if (field === "comments" || field === "work_notes") {
102
- throw new IncidentJournalPolicyError("generic_journal_update", field);
103
- }
104
- }
105
- }
106
119
  /** Defense-in-depth normalization for the fixed incident journal modules. */
107
120
  function prepareIncidentJournalArguments(args) {
108
121
  const identity = servicenow_identifiers_js_1.serviceNowSysIdSchema.safeParse(args.sys_id);
@@ -1 +1 @@
1
- {"version":3,"file":"incident-journal-policy.js","sourceRoot":"","sources":["../src/incident-journal-policy.ts"],"names":[],"mappings":";AAAA,2EAA2E;;;AAmF3E,oEAQC;AAGD,0EAeC;AAGD,gFAgBC;AAGD,0EASC;AA1ID,yCAAmD;AACnD,6BAAwB;AAExB,2EAAoE;AAEvD,QAAA,+BAA+B,GAAG,KAAK,CAAC;AACxC,QAAA,+BAA+B,GAAG,MAAM,CAAC;AAItD,MAAM,aAAa,GACjB,MAAM,CAAC,MAAM,CAAC;IACZ,QAAQ,EAAE,yBAAyB;IACnC,UAAU,EAAE,2BAA2B;CACxC,CAAC,CAAC;AACL,MAAM,qCAAqC,GAAG,IAAI,OAAO,EAAU,CAAC;AACpE,MAAM,kBAAkB,GAAG,kBAAkB,CAAC;AAC9C,MAAM,sBAAsB,GAC1B,0EAA0E,CAAC;AAEhE,QAAA,4BAA4B,GAAG,OAAC;KAC1C,MAAM,EAAE;IACT,uEAAuE;KACtE,GAAG,CAAC,uCAA+B,CAAC;KACpC,WAAW,CAAC,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;IAC9B,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC9B,OAAO,CAAC,QAAQ,CAAC;YACf,IAAI,EAAE,OAAC,CAAC,YAAY,CAAC,MAAM;YAC3B,OAAO,EAAE,iDAAiD;SAC3D,CAAC,CAAC;IACL,CAAC;IACD,IAAI,kBAAkB,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QACnC,OAAO,CAAC,QAAQ,CAAC;YACf,IAAI,EAAE,OAAC,CAAC,YAAY,CAAC,MAAM;YAC3B,OAAO,EAAE,sDAAsD;SAChE,CAAC,CAAC;IACL,CAAC;IACD,IAAI,sBAAsB,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QACvC,OAAO,CAAC,QAAQ,CAAC;YAC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,OAAO,GAAG,oCAA4B,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACrE,IAAI,CAAC,QAAQ,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;QAC1C,MAAM,IAAI,0BAA0B,CAAC,yBAAyB,CAAC,CAAC;IAClE,CAAC;IACD,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;AACzE,CAAC"}
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Structural bounds for untrusted JSON-RPC messages, checked before any
3
+ * schema validation runs.
4
+ *
5
+ * Schema libraries walk every element of a collection they validate and can
6
+ * record one issue (or one issue tree, for a union) per failing element. That
7
+ * work grows with the element count rather than the byte count, so a
8
+ * request well inside the body-size limit can still cost far more memory and
9
+ * time to reject than to accept. The protocol schemas for methods such as
10
+ * `initialize` and `prompts/get` run before any tool-level bound can apply,
11
+ * so this module is the only layer that covers them.
12
+ *
13
+ * {@link inspectJsonShape} is plain JavaScript, independent of the schema
14
+ * library and its version. It is a single iterative pass with an explicit
15
+ * stack (no recursion, so no call-stack limit to reach) and it stops at the
16
+ * first bound crossed.
17
+ *
18
+ * The bounds are derived from the largest input any tool legitimately
19
+ * accepts, so a request that passes every later policy check also passes
20
+ * here:
21
+ *
22
+ * - an array may hold at most {@link MAX_FIELD_ARRAY_LENGTH} elements, the
23
+ * field-policy bound for a single array value;
24
+ * - the message may hold at most {@link MAX_JSON_MESSAGE_ELEMENTS} array
25
+ * elements and object members in total: the tool-argument budget plus a
26
+ * fixed allowance for the JSON-RPC envelope;
27
+ * - no value may sit deeper than {@link MAX_JSON_MESSAGE_DEPTH} levels below
28
+ * the message root. The deepest legitimate value is a field-write value at
29
+ * the field-policy depth limit, reached through `params.arguments.fields`.
30
+ *
31
+ * @module json-shape-limits
32
+ */
33
+ /**
34
+ * Element budget for one tool call's arguments, as the SDK counts it (every
35
+ * array element and own object member below the arguments object).
36
+ *
37
+ * The largest legitimate call is a bulk write: a full field-value budget, a
38
+ * structured filter at the compiler's node bound, and the argument keys
39
+ * themselves. Every value in a field-write map counts once as a member of its
40
+ * parent, which is exactly how the field policy counts nodes.
41
+ */
42
+ export declare const MAX_TOOL_INPUT_ELEMENTS: number;
43
+ export declare const MAX_JSON_MESSAGE_ELEMENTS: number;
44
+ export declare const MAX_JSON_MESSAGE_ARRAY_LENGTH = 10000;
45
+ /**
46
+ * Root is depth 0. A field value sits at depth 4 (`params`, `arguments`,
47
+ * `fields`, the field) and may nest {@link MAX_FIELD_VALUE_DEPTH} levels
48
+ * further, which gives 28; the remainder is headroom for envelope changes.
49
+ */
50
+ export declare const MAX_JSON_MESSAGE_DEPTH: number;
51
+ export type JsonShapeViolation = "array_length" | "element_count" | "depth";
52
+ export interface JsonShapeLimits {
53
+ readonly maxArrayLength: number;
54
+ readonly maxElements: number;
55
+ readonly maxDepth: number;
56
+ }
57
+ export declare const JSON_MESSAGE_SHAPE_LIMITS: JsonShapeLimits;
58
+ /** Fixed rejection text. It never includes any part of the rejected input. */
59
+ export declare const JSON_SHAPE_REJECTION_MESSAGE = "Request exceeds structural limits.";
60
+ /** JSON-RPC "Invalid Request". */
61
+ export declare const JSON_SHAPE_REJECTION_CODE = -32600;
62
+ /**
63
+ * Check a parsed JSON value against structural bounds.
64
+ *
65
+ * Returns `undefined` when the value is within every bound, or the first bound
66
+ * it crosses. Only plain JSON data is expected (the output of `JSON.parse`),
67
+ * but anything that throws while being read is reported as a violation rather
68
+ * than propagated.
69
+ */
70
+ export declare function inspectJsonShape(value: unknown, limits?: JsonShapeLimits): JsonShapeViolation | undefined;
71
+ //# sourceMappingURL=json-shape-limits.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-shape-limits.d.ts","sourceRoot":"","sources":["../src/json-shape-limits.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAUH;;;;;;;;GAQG;AACH,eAAO,MAAM,uBAAuB,QAC6C,CAAC;AAKlF,eAAO,MAAM,yBAAyB,QAAwD,CAAC;AAC/F,eAAO,MAAM,6BAA6B,QAAyB,CAAC;AACpE;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,QAA4B,CAAC;AAEhE,MAAM,MAAM,kBAAkB,GAAG,cAAc,GAAG,eAAe,GAAG,OAAO,CAAC;AAE5E,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B;AAED,eAAO,MAAM,yBAAyB,EAAE,eAItC,CAAC;AAEH,8EAA8E;AAC9E,eAAO,MAAM,4BAA4B,uCAAuC,CAAC;AACjF,kCAAkC;AAClC,eAAO,MAAM,yBAAyB,SAAS,CAAC;AAEhD;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,OAAO,EACd,MAAM,GAAE,eAA2C,GAClD,kBAAkB,GAAG,SAAS,CA4ChC"}
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+ /**
3
+ * Structural bounds for untrusted JSON-RPC messages, checked before any
4
+ * schema validation runs.
5
+ *
6
+ * Schema libraries walk every element of a collection they validate and can
7
+ * record one issue (or one issue tree, for a union) per failing element. That
8
+ * work grows with the element count rather than the byte count, so a
9
+ * request well inside the body-size limit can still cost far more memory and
10
+ * time to reject than to accept. The protocol schemas for methods such as
11
+ * `initialize` and `prompts/get` run before any tool-level bound can apply,
12
+ * so this module is the only layer that covers them.
13
+ *
14
+ * {@link inspectJsonShape} is plain JavaScript, independent of the schema
15
+ * library and its version. It is a single iterative pass with an explicit
16
+ * stack (no recursion, so no call-stack limit to reach) and it stops at the
17
+ * first bound crossed.
18
+ *
19
+ * The bounds are derived from the largest input any tool legitimately
20
+ * accepts, so a request that passes every later policy check also passes
21
+ * here:
22
+ *
23
+ * - an array may hold at most {@link MAX_FIELD_ARRAY_LENGTH} elements, the
24
+ * field-policy bound for a single array value;
25
+ * - the message may hold at most {@link MAX_JSON_MESSAGE_ELEMENTS} array
26
+ * elements and object members in total: the tool-argument budget plus a
27
+ * fixed allowance for the JSON-RPC envelope;
28
+ * - no value may sit deeper than {@link MAX_JSON_MESSAGE_DEPTH} levels below
29
+ * the message root. The deepest legitimate value is a field-write value at
30
+ * the field-policy depth limit, reached through `params.arguments.fields`.
31
+ *
32
+ * @module json-shape-limits
33
+ */
34
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ exports.JSON_SHAPE_REJECTION_CODE = exports.JSON_SHAPE_REJECTION_MESSAGE = exports.JSON_MESSAGE_SHAPE_LIMITS = exports.MAX_JSON_MESSAGE_DEPTH = exports.MAX_JSON_MESSAGE_ARRAY_LENGTH = exports.MAX_JSON_MESSAGE_ELEMENTS = exports.MAX_TOOL_INPUT_ELEMENTS = void 0;
36
+ exports.inspectJsonShape = inspectJsonShape;
37
+ const field_policy_js_1 = require("./field-policy.js");
38
+ const structured_query_js_1 = require("./structured-query.js");
39
+ /**
40
+ * Element budget for one tool call's arguments, as the SDK counts it (every
41
+ * array element and own object member below the arguments object).
42
+ *
43
+ * The largest legitimate call is a bulk write: a full field-value budget, a
44
+ * structured filter at the compiler's node bound, and the argument keys
45
+ * themselves. Every value in a field-write map counts once as a member of its
46
+ * parent, which is exactly how the field policy counts nodes.
47
+ */
48
+ exports.MAX_TOOL_INPUT_ELEMENTS = field_policy_js_1.MAX_FIELD_VALUE_NODES + structured_query_js_1.MAX_STRUCTURED_QUERY_NODES + field_policy_js_1.MAX_TOOL_ARGUMENT_OWN_KEYS;
49
+ /** Members outside the tool arguments: `jsonrpc`, `id`, `method`, `params`, `_meta`, and so on. */
50
+ const JSON_RPC_ENVELOPE_ALLOWANCE = 64;
51
+ exports.MAX_JSON_MESSAGE_ELEMENTS = exports.MAX_TOOL_INPUT_ELEMENTS + JSON_RPC_ENVELOPE_ALLOWANCE;
52
+ exports.MAX_JSON_MESSAGE_ARRAY_LENGTH = field_policy_js_1.MAX_FIELD_ARRAY_LENGTH;
53
+ /**
54
+ * Root is depth 0. A field value sits at depth 4 (`params`, `arguments`,
55
+ * `fields`, the field) and may nest {@link MAX_FIELD_VALUE_DEPTH} levels
56
+ * further, which gives 28; the remainder is headroom for envelope changes.
57
+ */
58
+ exports.MAX_JSON_MESSAGE_DEPTH = field_policy_js_1.MAX_FIELD_VALUE_DEPTH + 8;
59
+ exports.JSON_MESSAGE_SHAPE_LIMITS = Object.freeze({
60
+ maxArrayLength: exports.MAX_JSON_MESSAGE_ARRAY_LENGTH,
61
+ maxElements: exports.MAX_JSON_MESSAGE_ELEMENTS,
62
+ maxDepth: exports.MAX_JSON_MESSAGE_DEPTH,
63
+ });
64
+ /** Fixed rejection text. It never includes any part of the rejected input. */
65
+ exports.JSON_SHAPE_REJECTION_MESSAGE = "Request exceeds structural limits.";
66
+ /** JSON-RPC "Invalid Request". */
67
+ exports.JSON_SHAPE_REJECTION_CODE = -32600;
68
+ /**
69
+ * Check a parsed JSON value against structural bounds.
70
+ *
71
+ * Returns `undefined` when the value is within every bound, or the first bound
72
+ * it crosses. Only plain JSON data is expected (the output of `JSON.parse`),
73
+ * but anything that throws while being read is reported as a violation rather
74
+ * than propagated.
75
+ */
76
+ function inspectJsonShape(value, limits = exports.JSON_MESSAGE_SHAPE_LIMITS) {
77
+ if (value === null || typeof value !== "object")
78
+ return undefined;
79
+ // Parallel stacks avoid allocating a pair per container. Only containers
80
+ // are pushed, and each push follows a counted member, so the stacks never
81
+ // grow past maxElements entries.
82
+ const values = [value];
83
+ const depths = [0];
84
+ let elements = 0;
85
+ try {
86
+ while (values.length > 0) {
87
+ const node = values.pop();
88
+ const childDepth = depths.pop() + 1;
89
+ if (Array.isArray(node)) {
90
+ const length = node.length;
91
+ if (length > limits.maxArrayLength)
92
+ return "array_length";
93
+ elements += length;
94
+ if (elements > limits.maxElements)
95
+ return "element_count";
96
+ if (length === 0)
97
+ continue;
98
+ if (childDepth > limits.maxDepth)
99
+ return "depth";
100
+ for (let index = 0; index < length; index += 1) {
101
+ const child = node[index];
102
+ if (child !== null && typeof child === "object") {
103
+ values.push(child);
104
+ depths.push(childDepth);
105
+ }
106
+ }
107
+ }
108
+ else {
109
+ for (const key in node) {
110
+ if (!Object.hasOwn(node, key))
111
+ continue;
112
+ elements += 1;
113
+ if (elements > limits.maxElements)
114
+ return "element_count";
115
+ if (childDepth > limits.maxDepth)
116
+ return "depth";
117
+ const child = node[key];
118
+ if (child !== null && typeof child === "object") {
119
+ values.push(child);
120
+ depths.push(childDepth);
121
+ }
122
+ }
123
+ }
124
+ }
125
+ }
126
+ catch {
127
+ return "element_count";
128
+ }
129
+ return undefined;
130
+ }
131
+ //# sourceMappingURL=json-shape-limits.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-shape-limits.js","sourceRoot":"","sources":["../src/json-shape-limits.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;;;AA6DH,4CA+CC;AA1GD,uDAK2B;AAC3B,+DAAmE;AAEnE;;;;;;;;GAQG;AACU,QAAA,uBAAuB,GAClC,uCAAqB,GAAG,gDAA0B,GAAG,4CAA0B,CAAC;AAElF,mGAAmG;AACnG,MAAM,2BAA2B,GAAG,EAAE,CAAC;AAE1B,QAAA,yBAAyB,GAAG,+BAAuB,GAAG,2BAA2B,CAAC;AAClF,QAAA,6BAA6B,GAAG,wCAAsB,CAAC;AACpE;;;;GAIG;AACU,QAAA,sBAAsB,GAAG,uCAAqB,GAAG,CAAC,CAAC;AAUnD,QAAA,yBAAyB,GAAoB,MAAM,CAAC,MAAM,CAAC;IACtE,cAAc,EAAE,qCAA6B;IAC7C,WAAW,EAAE,iCAAyB;IACtC,QAAQ,EAAE,8BAAsB;CACjC,CAAC,CAAC;AAEH,8EAA8E;AACjE,QAAA,4BAA4B,GAA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AC;wBAChD,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;wBACnB,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;oBAC1B,CAAC;gBACH,CAAC;YACH,CAAC;iBAAM,CAAC;gBACN,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;oBACvB,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,CAAC;wBAAE,SAAS;oBACxC,QAAQ,IAAI,CAAC,CAAC;oBACd,IAAI,QAAQ,GAAG,MAAM,CAAC,WAAW;wBAAE,OAAO,eAAe,CAAC;oBAC1D,IAAI,UAAU,GAAG,MAAM,CAAC,QAAQ;wBAAE,OAAO,OAAO,CAAC;oBACjD,MAAM,KAAK,GAAa,IAAgC,CAAC,GAAG,CAAC,CAAC;oBAC9D,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;wBAChD,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;wBACnB,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;oBAC1B,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,eAAe,CAAC;IACzB,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
@@ -5,33 +5,44 @@
5
5
  * selector. The scope must discriminate credential identity as well as
6
6
  * instance: ServiceNow evaluates ACLs per user, and a cache hit skips the
7
7
  * upstream read entirely, so a scope shared between identities would serve
8
- * one caller's authorized rows to another. A cache hit performs a lightweight
9
- * sys_updated_on probe before reuse; changed rows force a refresh. Callers can
10
- * force refresh by passing the internal sysparm_force_recache=true parameter,
11
- * which is stripped before upstream I/O.
8
+ * one caller's authorized rows to another. Callers can force refresh by
9
+ * passing the internal sysparm_force_recache=true parameter, which is stripped
10
+ * before upstream I/O.
12
11
  *
13
- * The freshness probe compares sys_updated_on, which ServiceNow evaluates in
14
- * the session user's timezone, so the probe timestamp is formatted in that
15
- * timezone rather than UTC. The zone is resolved per identity from
16
- * sys_user.time_zone, falling back to the glide.sys.default.tz property; when
17
- * it cannot be resolved, caching is disabled for that identity rather than
18
- * assuming UTC and serving silently stale metadata.
12
+ * Freshness is a server watermark: the table's row count (X-Total-Count) and
13
+ * its newest row by sys_updated_on, read back as the stored UTC value. Each
14
+ * entry keeps the watermark read just before its rows were fetched, and a
15
+ * cache hit is served only while a new watermark read still matches it. Both
16
+ * sides of the comparison come from the instance, so the session timezone,
17
+ * date format, DST and clock skew between this host and the instance play no
18
+ * part, and no user lookup is needed: caching behaves the same in every auth
19
+ * mode.
19
20
  *
20
- * Deletions are not detected by the probe, which sees updates only. A row
21
- * deleted upstream stays visible for at most one TTL: a successful probe
22
- * refreshes recency for eviction but never extends expiresAt, so the entry
23
- * still expires on schedule and forces a genuine refetch.
21
+ * An insert or an update makes its row the newest, and an insert or a delete
22
+ * changes the count, so every write moves the watermark -- at one-second
23
+ * resolution. An update within the stored watermark's own second, to a row
24
+ * other than the newest, can still go unseen; so can a write that skips the
25
+ * system fields. Such a row stays stale for at most one TTL: a matching
26
+ * watermark refreshes recency for eviction but never extends expiresAt, so the
27
+ * entry still expires on schedule and forces a genuine refetch.
28
+ *
29
+ * Two memos keep the watermark from costing more than it saves. Within one
30
+ * tool call each table's watermark is read once, however many reads of the
31
+ * table the call makes. Across calls, a table whose watermark proved unusable
32
+ * is read straight through, without a watermark, for a while: long for causes
33
+ * that persist (an incomplete or future-dated watermark, a 4xx), short for
34
+ * transient ones (429, 5xx, timeouts, network).
24
35
  *
25
36
  * @module metadata-cache
26
37
  */
27
- import type { ServiceNowOperations } from "./client.js";
38
+ import { type ServiceNowOperations } from "./client.js";
28
39
  export declare const DEFAULT_METADATA_CACHE_TTL_MS: number;
29
40
  /**
30
41
  * Tables cached by default.
31
42
  *
32
- * The bar for inclusion is a large payload relative to the freshness probe,
43
+ * The bar for inclusion is a large payload relative to the watermark read,
33
44
  * not merely "this table changes rarely" -- a cache hit still costs one
34
- * upstream round trip (see hasChangedSince), so the saving is payload bytes,
45
+ * upstream round trip (see tableWatermark), so the saving is payload bytes,
35
46
  * never request count. sys_properties is deliberately absent: its rows are
36
47
  * ACL-restricted per user and routinely hold integration secrets in `value`,
37
48
  * and the only reads of it here are three single-value build-info lookups
@@ -53,19 +64,33 @@ export declare const FORCE_RECACHE_PARAM = "sysparm_force_recache";
53
64
  * so both are capped and evicted in least-recently-used order. */
54
65
  export declare const MAX_METADATA_CACHE_SCOPES = 64;
55
66
  export declare const MAX_METADATA_CACHE_ENTRIES_PER_SCOPE = 512;
67
+ /** How long a table goes uncached after its watermark proved unusable; never
68
+ * longer than the cache TTL. */
69
+ export declare const STRUCTURAL_UNCACHEABLE_MS: number;
70
+ export declare const TRANSIENT_UNCACHEABLE_MS: number;
56
71
  interface MetadataCacheEnvironment {
57
72
  readonly SN_METADATA_CACHE_TTL_MS?: string;
58
73
  readonly SN_METADATA_CACHE_TABLES?: string;
59
74
  }
60
75
  export declare function metadataCacheConfigFromEnvironment(environment?: MetadataCacheEnvironment): MetadataCacheConfigInput;
61
76
  export declare function createMetadataCacheConfig(input: MetadataCacheConfigInput | undefined): MetadataCacheConfig;
77
+ /**
78
+ * The operations underneath a cached wrapper, or `operations` itself when it
79
+ * is not one.
80
+ *
81
+ * Use it for a read whose answer decides a write, such as the records a bulk
82
+ * update or delete targets. A cache hit can be stale within the watermark's
83
+ * documented gaps, which a read can tolerate but a write target cannot. The
84
+ * read costs one request, with no watermark, and leaves the cache untouched.
85
+ * The internal force-recache parameter is no substitute: it costs a watermark
86
+ * read as well, stores a single-use entry, and reaches ServiceNow unstripped
87
+ * when no wrapper is in place.
88
+ */
89
+ export declare function uncachedOperations(operations: ServiceNowOperations): ServiceNowOperations;
62
90
  /**
63
91
  * @param scope Cache partition key. Must identify the ServiceNow instance
64
92
  * *and* the credential identity reading from it -- see the module docstring.
65
- * @param sessionUserName ServiceNow user_name this scope authenticates as.
66
- * Required to resolve the session timezone; without it the freshness probe
67
- * cannot be made correct, so caching is disabled for the scope.
68
93
  */
69
- export declare function createCachedServiceNowOperations(operations: ServiceNowOperations, scope: string, config: MetadataCacheConfigInput | undefined, sessionUserName?: string): ServiceNowOperations;
94
+ export declare function createCachedServiceNowOperations(operations: ServiceNowOperations, scope: string, config: MetadataCacheConfigInput | undefined): ServiceNowOperations;
70
95
  export {};
71
96
  //# sourceMappingURL=metadata-cache.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"metadata-cache.d.ts","sourceRoot":"","sources":["../src/metadata-cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,KAAK,EAEV,oBAAoB,EACrB,MAAM,aAAa,CAAC;AAIrB,eAAO,MAAM,6BAA6B,QAAsB,CAAC;AACjE;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,6BAA6B,mBAQxC,CAAC;AAEH,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACrC;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;CACpC;AAcD,eAAO,MAAM,mBAAmB,0BAA0B,CAAC;AAG3D;;kEAEkE;AAClE,eAAO,MAAM,yBAAyB,KAAK,CAAC;AAC5C,eAAO,MAAM,oCAAoC,MAAM,CAAC;AAmBxD,UAAU,wBAAwB;IAChC,QAAQ,CAAC,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAC3C,QAAQ,CAAC,wBAAwB,CAAC,EAAE,MAAM,CAAC;CAC5C;AAED,wBAAgB,kCAAkC,CAChD,WAAW,GAAE,wBAAkE,GAC9E,wBAAwB,CAW1B;AAED,wBAAgB,yBAAyB,CACvC,KAAK,EA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