@tenonhq/dovetail-servicenow 0.0.54 → 0.0.56

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -913,12 +913,43 @@ switches the executing user's app scope + update set server-side, inserts, and
913
913
  restores both — so the record is owned by the right app and the insert is captured
914
914
  in the right update set. Like `set-field` it **refuses** schema tables and verifies
915
915
  via read-back. It also **refuses** `sys_update_set` — the op cannot set an update
916
- set's application, so create sets with `dove createUpdateSet` instead. `--scope` and `--update-set` are required; `--if-absent
916
+ set's application, so create sets with `dove createUpdateSet` instead. `--scope` and `--update-set` are required. `--scope` takes a scope name or a
917
+ `sys_scope` sys_id. Every global-scope app (e.g. the Dovetail app) has the scope name
918
+ `global`, which always means the Global scope itself, so reach a specific global app by its
919
+ sys_id. The server answers an unknown scope with 404, and a name shared by several apps with
920
+ 409, instead of falling back to your session scope; the record gets both `sys_scope` and
921
+ `sys_package`. `--if-absent
917
922
  "<encoded-query>"` makes re-runs idempotent (the insert is skipped when the query
918
923
  already matches a row). Exit codes: `0` created / skipped-in-sync / dry-run, `1` bad
919
924
  args, `2` write landed unverified (or skipped with drift). To **update** an existing
920
925
  record instead, use `set-field`.
921
926
 
927
+ #### Session domain (`--domain`, domain-separated instances)
928
+
929
+ `set-field`, `create-record`, `add-choices` and `remove-choices` (and their MCP tools
930
+ `set_field`, `create_record`, `add_choices_to_field`, `remove_choices_from_field`, as
931
+ `domain`) take `--domain <global|domain sys_id>`, **default `global`**. It is the session
932
+ domain the server op runs the write in. On a domain-separated instance the API user's
933
+ session starts in its own domain (`sys_user.sys_domain`), and that domain decides two
934
+ things the HTTP response never mentions:
935
+
936
+ - **Insert** — the new row is stamped with the session domain. A `sys_domain` in the
937
+ payload does not override it. (`create-record` without `--domain` uses the payload's
938
+ `sys_domain` as the session domain; both given and different is refused.)
939
+ - **Update of a process record** (`sys_script`, `sys_choice`, ...) that lives in a domain
940
+ *above* the session's — the platform does **not** edit it. It creates a domain
941
+ **override**: a new row in the session domain whose `sys_overrides` points at the
942
+ original, which stays unchanged.
943
+
944
+ The server op switches the session domain before the write and restores it afterwards,
945
+ and echoes `domain: { requested, applied, previous }`. It fails closed (nothing written)
946
+ if the switch does not take. Every verb then reads back **across domains**
947
+ (`sysparm_query_no_domain=true`) and reports `failed` / exits `2` with
948
+ `DOMAIN CHECK FAILED` when the record's `sys_domain` is not the expected one or a new
949
+ override row appeared. If the instance's op predates domain selection (no echo), the
950
+ message says so — deploy `servicenow/dovetail/sys_ws_operation/{pushWithUpdateSet,createRecord}.js`
951
+ to the Dovetail Core definition. Tables without `sys_domain` skip every domain check.
952
+
922
953
  #### Field sources (`--fields`, `--from-json`, `--from-stdin`)
923
954
 
924
955
  Both verbs take their field map from any combination of three sources; on a shared
package/dist/choices.js CHANGED
@@ -13,6 +13,7 @@ exports.ChoiceWriteError = void 0;
13
13
  exports.encodeQueryValue = encodeQueryValue;
14
14
  exports.addChoicesToField = addChoicesToField;
15
15
  exports.removeChoicesFromField = removeChoicesFromField;
16
+ const domain_1 = require("./domain");
16
17
  /**
17
18
  * Thrown when a choices write fails partway through the value loop.
18
19
  *
@@ -282,6 +283,35 @@ function buildChoiceFields(table, column, choice, scope) {
282
283
  }
283
284
  return fields;
284
285
  }
286
+ /** Normalise params.domain, naming the verb in the error. */
287
+ function resolveVerbDomain(verb, domain) {
288
+ try {
289
+ return (0, domain_1.normalizeDomain)(domain);
290
+ }
291
+ catch (e) {
292
+ throw new Error(verb + ": " + (e instanceof Error ? e.message : String(e)));
293
+ }
294
+ }
295
+ /** Snapshot of the overrides that already point at the rows a run will update. */
296
+ async function overrideBaseline(client, existing, toUpdate) {
297
+ var supported = existing.length > 0 &&
298
+ (0, domain_1.rowSupportsOverrides)(existing[0]);
299
+ if (!supported || toUpdate.length === 0) {
300
+ return { supported: supported, before: [] };
301
+ }
302
+ return {
303
+ supported: true,
304
+ before: await (0, domain_1.findOverrides)(client, "sys_choice", toUpdate),
305
+ };
306
+ }
307
+ function noWriteDomainCheck(domain) {
308
+ return {
309
+ requested: domain,
310
+ serverAcknowledged: true,
311
+ overridesCreated: [],
312
+ problems: [],
313
+ };
314
+ }
285
315
  function isUnchanged(existing, choice) {
286
316
  var sameLabel = existing.label === choice.label;
287
317
  var sameLang = (existing.language || "en") === (choice.language || "en");
@@ -310,6 +340,10 @@ async function addChoicesToField(client, params) {
310
340
  // Strict equality on purpose: a truthy-but-not-true value (the string "false" from a
311
341
  // mis-parsed flag, say) must not silently turn a planned run into a live write.
312
342
  var dryRun = params.dryRun === true;
343
+ var domain = resolveVerbDomain("add-choices", params.domain);
344
+ var acknowledged = true;
345
+ var createdIds = [];
346
+ var updatedIds = [];
313
347
  var dict = await fetchDictionary(client, params.table, params.column);
314
348
  var updateSet = await fetchUpdateSet(client, params.updateSetSysId);
315
349
  var scopeName = await resolveScopeName(client, dict.sys_scope);
@@ -322,12 +356,14 @@ async function addChoicesToField(client, params) {
322
356
  var choiceNow = choiceWas;
323
357
  if (params.choiceType !== null && Number(dict.choice) !== targetChoiceType) {
324
358
  if (!dryRun) {
325
- await client.claude.pushWithUpdateSet({
359
+ var dictResp = await client.claude.pushWithUpdateSet({
326
360
  update_set_sys_id: params.updateSetSysId,
327
361
  table: "sys_dictionary",
328
362
  record_sys_id: dict.sys_id,
329
363
  fields: { choice: String(targetChoiceType) },
364
+ domain: domain,
330
365
  });
366
+ acknowledged = acknowledged && (0, domain_1.readServerDomainEcho)(dictResp) !== null;
331
367
  }
332
368
  choiceNow = targetChoiceType;
333
369
  }
@@ -341,6 +377,11 @@ async function addChoicesToField(client, params) {
341
377
  return c.value;
342
378
  })));
343
379
  var existingByValue = groupExistingByKey(existing);
380
+ // Pre-write override baseline for every row this run will UPDATE, so an update the
381
+ // platform diverts into a domain override is caught on read-back.
382
+ var addBaseline = dryRun
383
+ ? { supported: false, before: [] }
384
+ : await overrideBaseline(client, existing, staleRowIds(choices, existingByValue));
344
385
  var results = [];
345
386
  for (var i = 0; i < choices.length; i += 1) {
346
387
  var choice = choices[i];
@@ -385,12 +426,15 @@ async function addChoicesToField(client, params) {
385
426
  }
386
427
  try {
387
428
  for (var s = 0; s < stale.length; s += 1) {
388
- await client.claude.pushWithUpdateSet({
429
+ var updResp = await client.claude.pushWithUpdateSet({
389
430
  update_set_sys_id: params.updateSetSysId,
390
431
  table: "sys_choice",
391
432
  record_sys_id: stale[s].sys_id,
392
433
  fields: updFields,
434
+ domain: domain,
393
435
  });
436
+ acknowledged = acknowledged && (0, domain_1.readServerDomainEcho)(updResp) !== null;
437
+ updatedIds.push(stale[s].sys_id);
394
438
  }
395
439
  }
396
440
  catch (e) {
@@ -424,11 +468,16 @@ async function addChoicesToField(client, params) {
424
468
  fields: buildChoiceFields(params.table, params.column, choice, dict.sys_scope),
425
469
  scope: scopeName,
426
470
  update_set_sys_id: params.updateSetSysId,
471
+ domain: domain,
427
472
  });
428
473
  }
429
474
  catch (e) {
430
475
  throw new ChoiceWriteError("add-choices", choice.value, results, e);
431
476
  }
477
+ acknowledged = acknowledged && (0, domain_1.readServerDomainEcho)(created) !== null;
478
+ if (created && created.sys_id) {
479
+ createdIds.push(String(created.sys_id));
480
+ }
432
481
  results.push({
433
482
  value: choice.value,
434
483
  label: choice.label,
@@ -452,8 +501,32 @@ async function addChoicesToField(client, params) {
452
501
  updateSet: { sysId: updateSet.sys_id, name: updateSet.name },
453
502
  dryRun: dryRun,
454
503
  choices: results,
504
+ domain: dryRun
505
+ ? noWriteDomainCheck(domain)
506
+ : await (0, domain_1.auditWrittenRows)({
507
+ client: client,
508
+ table: "sys_choice",
509
+ domain: domain,
510
+ createdIds: createdIds,
511
+ updatedIds: updatedIds,
512
+ overridesSupported: addBaseline.supported,
513
+ overridesBefore: addBaseline.before,
514
+ serverAcknowledged: acknowledged,
515
+ }),
455
516
  };
456
517
  }
518
+ /** sys_ids of every existing row the add pass will rewrite (mirrors the loop's stale filter). */
519
+ function staleRowIds(choices, existingByValue) {
520
+ var ids = [];
521
+ choices.forEach(function (choice) {
522
+ var key = (choice.language || "en") + "::" + choice.value;
523
+ (existingByValue[key] || []).forEach(function (row) {
524
+ if (!isUnchanged(row, choice))
525
+ ids.push(row.sys_id);
526
+ });
527
+ });
528
+ return ids;
529
+ }
457
530
  /**
458
531
  * Soft-delete choice values for a field: set `inactive=true` on each matching
459
532
  * sys_choice row via pushWithUpdateSet. NEVER a hard delete — the row stays, so the
@@ -499,6 +572,9 @@ async function removeChoicesFromField(client, params) {
499
572
  var language = params.language || "en";
500
573
  // Strict equality on purpose — see addChoicesToField.
501
574
  var dryRun = params.dryRun === true;
575
+ var domain = resolveVerbDomain("remove-choices", params.domain);
576
+ var removeAcknowledged = true;
577
+ var deactivatedIds = [];
502
578
  // fetchDictionary throws a clear error when the field does not exist; fetchUpdateSet
503
579
  // throws unless the set is in progress. Both mirror the add path's guards.
504
580
  var dict = await fetchDictionary(client, params.table, params.column);
@@ -510,6 +586,16 @@ async function removeChoicesFromField(client, params) {
510
586
  // scoped to the request rather than the whole field.
511
587
  var existing = await fetchExistingChoices(client, params.table, params.column, values);
512
588
  var existingByValue = groupExistingByKey(existing);
589
+ var toDeactivate = [];
590
+ values.forEach(function (v) {
591
+ (existingByValue[language + "::" + v] || []).forEach(function (row) {
592
+ if (row.inactive !== "true")
593
+ toDeactivate.push(row.sys_id);
594
+ });
595
+ });
596
+ var removeBaseline = dryRun
597
+ ? { supported: false, before: [] }
598
+ : await overrideBaseline(client, existing, toDeactivate);
513
599
  var results = [];
514
600
  for (var i = 0; i < values.length; i += 1) {
515
601
  var value = values[i];
@@ -558,12 +644,16 @@ async function removeChoicesFromField(client, params) {
558
644
  }
559
645
  try {
560
646
  for (var a = 0; a < active.length; a += 1) {
561
- await client.claude.pushWithUpdateSet({
647
+ var deactResp = await client.claude.pushWithUpdateSet({
562
648
  update_set_sys_id: params.updateSetSysId,
563
649
  table: "sys_choice",
564
650
  record_sys_id: active[a].sys_id,
565
651
  fields: { inactive: "true" },
652
+ domain: domain,
566
653
  });
654
+ removeAcknowledged =
655
+ removeAcknowledged && (0, domain_1.readServerDomainEcho)(deactResp) !== null;
656
+ deactivatedIds.push(active[a].sys_id);
567
657
  }
568
658
  }
569
659
  catch (e) {
@@ -587,5 +677,17 @@ async function removeChoicesFromField(client, params) {
587
677
  updateSet: { sysId: updateSet.sys_id, name: updateSet.name },
588
678
  dryRun: dryRun,
589
679
  choices: results,
680
+ domain: dryRun
681
+ ? noWriteDomainCheck(domain)
682
+ : await (0, domain_1.auditWrittenRows)({
683
+ client: client,
684
+ table: "sys_choice",
685
+ domain: domain,
686
+ createdIds: [],
687
+ updatedIds: deactivatedIds,
688
+ overridesSupported: removeBaseline.supported,
689
+ overridesBefore: removeBaseline.before,
690
+ serverAcknowledged: removeAcknowledged,
691
+ }),
590
692
  };
591
693
  }
package/dist/cli.d.ts CHANGED
@@ -28,5 +28,15 @@ interface ParsedArgs {
28
28
  positional: Array<string>;
29
29
  }
30
30
  export declare function parseArgs(argv: Array<string>): ParsedArgs;
31
+ /**
32
+ * --domain for the record-write verbs (set-field, create-record, add-choices,
33
+ * remove-choices): the session domain the write runs in. Absent → undefined, and the
34
+ * verb defaults to "global". A bare flag or a value that is neither "global" nor a
35
+ * 32-hex sys_id is refused — a typo must never silently fall back to the default.
36
+ */
37
+ export declare function domainFlag(verb: string, flags: Record<string, string>, bare: Record<string, boolean>): {
38
+ domain?: string;
39
+ error?: string;
40
+ };
31
41
  export declare function main(argv: Array<string>): Promise<number>;
32
42
  export {};
package/dist/cli.js CHANGED
@@ -47,6 +47,7 @@ var __importStar = (this && this.__importStar) || (function () {
47
47
  })();
48
48
  Object.defineProperty(exports, "__esModule", { value: true });
49
49
  exports.parseArgs = parseArgs;
50
+ exports.domainFlag = domainFlag;
50
51
  exports.main = main;
51
52
  const fs = __importStar(require("fs"));
52
53
  const path = __importStar(require("path"));
@@ -82,6 +83,7 @@ const testFlow_1 = require("./flowDesigner/testFlow");
82
83
  const table_1 = require("./table");
83
84
  const setField_1 = require("./setField");
84
85
  const createRecord_1 = require("./createRecord");
86
+ const domain_1 = require("./domain");
85
87
  const deleteRecord_1 = require("./deleteRecord");
86
88
  const invokeRest_1 = require("./invokeRest");
87
89
  const publishApp_1 = require("./publishApp");
@@ -173,6 +175,33 @@ function bareStringFlagError(verb, bare) {
173
175
  }
174
176
  return null;
175
177
  }
178
+ /**
179
+ * --domain for the record-write verbs (set-field, create-record, add-choices,
180
+ * remove-choices): the session domain the write runs in. Absent → undefined, and the
181
+ * verb defaults to "global". A bare flag or a value that is neither "global" nor a
182
+ * 32-hex sys_id is refused — a typo must never silently fall back to the default.
183
+ */
184
+ function domainFlag(verb, flags, bare) {
185
+ if (bare && bare.domain) {
186
+ return { error: verb + ": --domain needs a value (\"global\" or a domain sys_id).\n" };
187
+ }
188
+ if (!flags || flags.domain === undefined) {
189
+ return {};
190
+ }
191
+ try {
192
+ return { domain: (0, domain_1.normalizeDomain)(flags.domain) };
193
+ }
194
+ catch (e) {
195
+ return { error: verb + ": --" + (e instanceof Error ? e.message : String(e)) + "\n" };
196
+ }
197
+ }
198
+ /** Print a choices verb's domain failure (if any) and return the exit code it implies. */
199
+ function choicesDomainExit(check) {
200
+ if (!check || check.problems.length === 0)
201
+ return 0;
202
+ process.stderr.write((0, domain_1.multiRowDomainNote)(check, "pushWithUpdateSet / createRecord") + "\n");
203
+ return 2;
204
+ }
176
205
  async function runAddChoices(flags, bare) {
177
206
  // `updateSetSysId` is guarded alongside `update-set` because paramsFromFlags accepts
178
207
  // both spellings — guarding only the dashed one leaves the alias as a way in.
@@ -181,20 +210,29 @@ async function runAddChoices(flags, bare) {
181
210
  process.stderr.write(bareErr);
182
211
  return 1;
183
212
  }
213
+ var addDomain = domainFlag("add-choices", flags, bare);
214
+ if (addDomain.error) {
215
+ process.stderr.write(addDomain.error);
216
+ return 1;
217
+ }
184
218
  var params = paramsFromFlags(flags);
185
219
  // The flag is parsed for every verb; this verb used to drop it on the floor and WRITE
186
220
  // (#296). Threading it here is what makes --dry-run a real plan, not a label.
187
221
  if (flags["dry-run"] === "true") {
188
222
  params.dryRun = true;
189
223
  }
224
+ // The flag wins over a --from-json spec's own "domain".
225
+ if (addDomain.domain !== undefined) {
226
+ params.domain = addDomain.domain;
227
+ }
190
228
  var client = (0, client_1.createClient)({});
191
229
  var result = await (0, choices_1.addChoicesToField)(client, params);
192
230
  if (flags.json === "true") {
193
231
  process.stdout.write(JSON.stringify({ params: params, result: result }, null, 2) + "\n");
194
- return 0;
232
+ return choicesDomainExit(result.domain);
195
233
  }
196
234
  process.stdout.write((0, formatter_1.formatAddChoicesResult)(params.table, params.column, result) + "\n");
197
- return 0;
235
+ return choicesDomainExit(result.domain);
198
236
  }
199
237
  function removeParamsFromFlags(flags) {
200
238
  if (flags["from-json"]) {
@@ -238,18 +276,26 @@ async function runRemoveChoices(flags, bare) {
238
276
  process.stderr.write(bareErr);
239
277
  return 1;
240
278
  }
279
+ var removeDomain = domainFlag("remove-choices", flags, bare);
280
+ if (removeDomain.error) {
281
+ process.stderr.write(removeDomain.error);
282
+ return 1;
283
+ }
241
284
  var params = removeParamsFromFlags(flags);
242
285
  if (flags["dry-run"] === "true") {
243
286
  params.dryRun = true;
244
287
  }
288
+ if (removeDomain.domain !== undefined) {
289
+ params.domain = removeDomain.domain;
290
+ }
245
291
  var client = (0, client_1.createClient)({});
246
292
  var result = await (0, choices_1.removeChoicesFromField)(client, params);
247
293
  if (flags.json === "true") {
248
294
  process.stdout.write(JSON.stringify({ params: params, result: result }, null, 2) + "\n");
249
- return 0;
295
+ return choicesDomainExit(result.domain);
250
296
  }
251
297
  process.stdout.write((0, formatter_1.formatRemoveChoicesResult)(params.table, params.column, result) + "\n");
252
- return 0;
298
+ return choicesDomainExit(result.domain);
253
299
  }
254
300
  /**
255
301
  * dove-sn build-flow:
@@ -1971,10 +2017,17 @@ function getProcessStdin() {
1971
2017
  * way stdin is ever read; never implicit)
1972
2018
  * — at least one field source is required
1973
2019
  * --update-set <sys_id> (required — the change is captured here)
2020
+ * [--domain global|<domain sys_id>] (session domain for the write; default global)
1974
2021
  * [--dry-run] [--json]
1975
- * Exit codes: 0 applied/dry-run, 1 bad args, 2 write landed but read-back unverified.
2022
+ * Exit codes: 0 applied/dry-run, 1 bad args, 2 write landed but read-back unverified
2023
+ * (including a sys_domain change or a domain OVERRIDE row created instead of an in-place update).
1976
2024
  */
1977
- async function runSetField(flags) {
2025
+ async function runSetField(flags, bare) {
2026
+ var setDomain = domainFlag("set-field", flags, bare || {});
2027
+ if (setDomain.error) {
2028
+ process.stderr.write(setDomain.error);
2029
+ return 1;
2030
+ }
1978
2031
  var table = flags.table;
1979
2032
  var fields;
1980
2033
  try {
@@ -2004,6 +2057,8 @@ async function runSetField(flags) {
2004
2057
  params.query = flags.query;
2005
2058
  if (flags["dry-run"] === "true")
2006
2059
  params.dryRun = true;
2060
+ if (setDomain.domain !== undefined)
2061
+ params.domain = setDomain.domain;
2007
2062
  var result = await (0, setField_1.setField)(params);
2008
2063
  if (flags.json === "true") {
2009
2064
  process.stdout.write(JSON.stringify(result, null, 2) + "\n");
@@ -2038,11 +2093,18 @@ async function runSetField(flags) {
2038
2093
  * --scope x_cadso_core (the app that owns the new record)
2039
2094
  * --update-set <sys_id> (required — the insert is captured here)
2040
2095
  * [--if-absent "name=avg_message_parts"] (skip the insert when this query already matches)
2096
+ * [--domain global|<domain sys_id>] (session domain for the insert; default global,
2097
+ * or the payload's sys_domain when it carries one)
2041
2098
  * [--dry-run] [--json]
2042
2099
  * Exit codes: 0 created/skipped-in-sync/dry-run, 1 bad args, 2 write landed but read-back unverified
2043
2100
  * (or skipped with drift).
2044
2101
  */
2045
- async function runCreateRecord(flags) {
2102
+ async function runCreateRecord(flags, bare) {
2103
+ var createDomain = domainFlag("create-record", flags, bare || {});
2104
+ if (createDomain.error) {
2105
+ process.stderr.write(createDomain.error);
2106
+ return 1;
2107
+ }
2046
2108
  var table = flags.table;
2047
2109
  var fields;
2048
2110
  try {
@@ -2072,6 +2134,8 @@ async function runCreateRecord(flags) {
2072
2134
  params.ifAbsentQuery = flags["if-absent"];
2073
2135
  if (flags["dry-run"] === "true")
2074
2136
  params.dryRun = true;
2137
+ if (createDomain.domain !== undefined)
2138
+ params.domain = createDomain.domain;
2075
2139
  var result = await (0, createRecord_1.createRecord)(params);
2076
2140
  if (flags.json === "true") {
2077
2141
  process.stdout.write(JSON.stringify(result, null, 2) + "\n");
@@ -2864,10 +2928,10 @@ async function dispatch(parsed) {
2864
2928
  return await runSetTable(parsed.flags, parsed.bare);
2865
2929
  }
2866
2930
  if (parsed.command === "set-field") {
2867
- return await runSetField(parsed.flags);
2931
+ return await runSetField(parsed.flags, parsed.bare);
2868
2932
  }
2869
2933
  if (parsed.command === "create-record") {
2870
- return await runCreateRecord(parsed.flags);
2934
+ return await runCreateRecord(parsed.flags, parsed.bare);
2871
2935
  }
2872
2936
  if (parsed.command === "sync-ux-events") {
2873
2937
  return await runSyncUxEvents(parsed.flags, parsed.bare);
package/dist/cliUsage.js CHANGED
@@ -64,6 +64,11 @@ var UPDATE_SET_FLAG = {
64
64
  value: "<sys_id>",
65
65
  note: "Update set that captures every write (alias: --updateSetSysId).",
66
66
  };
67
+ var DOMAIN_FLAG = {
68
+ flag: "domain",
69
+ value: "<global|domain sys_id>",
70
+ note: "Session domain the write runs in (default global). On a domain-separated instance the read-back also verifies sys_domain and that no domain override row was created.",
71
+ };
67
72
  var DEBUG_FLAG = {
68
73
  flag: "debug",
69
74
  note: "Verbose request/response tracing on stderr.",
@@ -96,6 +101,7 @@ exports.VERB_USAGE = {
96
101
  value: "<path>",
97
102
  note: 'Replaces the flags above. JSON { "table", "column", "updateSetSysId", "choiceType"?, "choices": [{ "value", "label" }] }.',
98
103
  },
104
+ DOMAIN_FLAG,
99
105
  {
100
106
  flag: "dry-run",
101
107
  note: "Verify the field + update set and print [would create] / [would update] rows; nothing is written.",
@@ -113,6 +119,7 @@ exports.VERB_USAGE = {
113
119
  "choices",
114
120
  "from-json",
115
121
  "choice-type",
122
+ "domain",
116
123
  ],
117
124
  },
118
125
  "remove-choices": {
@@ -130,6 +137,7 @@ exports.VERB_USAGE = {
130
137
  value: "<path>",
131
138
  note: 'Replaces the flags above. JSON { "table", "column", "updateSetSysId", "values": [...], "language"? } — validated against the MCP schema.',
132
139
  },
140
+ DOMAIN_FLAG,
133
141
  {
134
142
  flag: "dry-run",
135
143
  note: "Verify the field + update set and print [would deactivate] rows; nothing is written.",
@@ -147,6 +155,7 @@ exports.VERB_USAGE = {
147
155
  "values",
148
156
  "language",
149
157
  "from-json",
158
+ "domain",
150
159
  ],
151
160
  },
152
161
  "create-table": {
@@ -407,10 +416,12 @@ exports.VERB_USAGE = {
407
416
  note: "At least one. --from-json / --from-stdin (alias --from-json -) take a JSON { field: value } object, win on a shared key, and are the only forms for large or multiline values. stdin is read ONLY with --from-stdin.",
408
417
  },
409
418
  ],
410
- optional: [DRY_RUN_FLAG, JSON_FLAG],
419
+ optional: [DOMAIN_FLAG, DRY_RUN_FLAG, JSON_FLAG],
411
420
  gate: "dry-run-flag",
412
421
  example: 'dove-sn set-field --table x_cadso_core_metric_point_type --query "name=send_size" --fields "order=20" --update-set <sys_id>',
413
- notes: ["Exit 2 when the write landed but the read-back is unverified."],
422
+ notes: [
423
+ "Exit 2 when the write landed but the read-back is unverified — including a sys_domain change, or a domain OVERRIDE row the platform created instead of updating the record in place (the write ran in a session domain below the record's).",
424
+ ],
414
425
  },
415
426
  "create-record": {
416
427
  summary: "Create ONE NEW record in a data table, into an update set, then verify",
@@ -425,13 +436,17 @@ exports.VERB_USAGE = {
425
436
  },
426
437
  ],
427
438
  optional: [
428
- { flag: "if-absent", value: "<encoded-query>", note: "Skip the insert when this query already matches a row." },
439
+ { flag: "if-absent", value: "<encoded-query>", note: "Skip the insert when this query already matches a row (in any domain)." },
440
+ DOMAIN_FLAG,
429
441
  DRY_RUN_FLAG,
430
442
  JSON_FLAG,
431
443
  ],
432
444
  gate: "dry-run-flag",
433
445
  example: 'dove-sn create-record --table x_cadso_core_metric_point_type --scope x_cadso_core --fields "name=avg_parts,label=Avg Parts,order=35" --if-absent "name=avg_parts" --update-set <sys_id>',
434
- notes: ["Exit 2 when the write landed but the read-back is unverified (or --if-absent skipped with drift)."],
446
+ notes: [
447
+ "Exit 2 when the write landed but the read-back is unverified (or --if-absent skipped with drift, including a row in the wrong domain).",
448
+ "A sys_domain in the fields payload is not enough on its own — the platform stamps the session domain on insert. Without --domain the payload's sys_domain is used as the session domain; both given and different is refused.",
449
+ ],
435
450
  },
436
451
  "delete-record": {
437
452
  summary: "Delete ONE EXISTING data record, then read it back to verify it is GONE",
package/dist/client.d.ts CHANGED
@@ -65,6 +65,14 @@ export interface TableQueryOptions {
65
65
  * non-negative integer; omitted → not sent (ServiceNow default 0).
66
66
  */
67
67
  offset?: number;
68
+ /**
69
+ * Read across every domain (sysparm_query_no_domain=true). On a domain-separated
70
+ * instance a session in a child domain does not see rows in sibling domains, and a
71
+ * process record that has a domain override is HIDDEN behind the override — so a
72
+ * by-sys_id read-back after a write can come back empty or show the wrong row.
73
+ * Ignored by instances without domain separation.
74
+ */
75
+ noDomain?: boolean;
68
76
  }
69
77
  export interface TableSchemaField {
70
78
  name: string;
@@ -134,6 +142,12 @@ export interface ServiceNowClient {
134
142
  scope?: string;
135
143
  update_set_sys_id?: string;
136
144
  sys_id?: string;
145
+ /**
146
+ * Session domain to run the insert in: "global" or a domain sys_id. The op
147
+ * switches the session domain around the insert and restores it; an op that
148
+ * predates domain selection ignores the key (see domain.ts).
149
+ */
150
+ domain?: string;
137
151
  }) => Promise<{
138
152
  sys_id: string;
139
153
  [k: string]: any;
@@ -144,6 +158,12 @@ export interface ServiceNowClient {
144
158
  table: string;
145
159
  record_sys_id: string;
146
160
  fields: Record<string, unknown>;
161
+ /**
162
+ * Session domain to run the update in: "global" or a domain sys_id. An update of
163
+ * a process record from a session BELOW the record's domain creates a domain
164
+ * override instead of editing the record — see domain.ts.
165
+ */
166
+ domain?: string;
147
167
  }) => Promise<{
148
168
  sys_id: string;
149
169
  [k: string]: any;
package/dist/client.js CHANGED
@@ -337,6 +337,7 @@ function createClient(config = {}) {
337
337
  var limit = 100;
338
338
  var fields;
339
339
  var offset;
340
+ var noDomain = false;
340
341
  if (typeof limitOrOptions === "number") {
341
342
  limit = limitOrOptions;
342
343
  }
@@ -354,6 +355,7 @@ function createClient(config = {}) {
354
355
  }
355
356
  offset = rawOffset;
356
357
  }
358
+ noDomain = limitOrOptions.noDomain === true;
357
359
  }
358
360
  var params = {
359
361
  sysparm_query: query,
@@ -366,6 +368,9 @@ function createClient(config = {}) {
366
368
  if (offset !== undefined) {
367
369
  params.sysparm_offset = offset;
368
370
  }
371
+ if (noDomain) {
372
+ params.sysparm_query_no_domain = true;
373
+ }
369
374
  var data = await request({
370
375
  method: "GET",
371
376
  url: "/api/now/table/" + encodeURIComponent(table),
@@ -25,6 +25,13 @@ export interface CreateRecordParams {
25
25
  updateSetSysId?: string;
26
26
  /** Encoded query; when it already matches a row the insert is skipped (idempotent re-runs). */
27
27
  ifAbsentQuery?: string;
28
+ /**
29
+ * Session domain to insert in: "global" or a domain sys_id. Defaults to the
30
+ * payload's own sys_domain when it carries one, else "global". On a
31
+ * domain-separated instance the platform stamps the SESSION domain on an insert
32
+ * and ignores a sys_domain in the payload — so the domain must be chosen here.
33
+ */
34
+ domain?: string;
28
35
  dryRun?: boolean;
29
36
  }
30
37
  export interface CreateRecordResult extends RecordWriteResult {
@@ -32,3 +39,10 @@ export interface CreateRecordResult extends RecordWriteResult {
32
39
  scope: string;
33
40
  }
34
41
  export declare function createRecord(params: CreateRecordParams): Promise<CreateRecordResult>;
42
+ /**
43
+ * The session domain for an insert: an explicit `domain` wins; otherwise the
44
+ * payload's own sys_domain (the platform ignores it on insert, so honour it by
45
+ * running the insert in that domain); otherwise "global". Both given and
46
+ * different is a contradiction and refused.
47
+ */
48
+ export declare function resolveCreateDomain(params: CreateRecordParams): string;